aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-06-22 11:16:09 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-06-27 11:06:51 +0200
commit6cffa97b036ab628b91998cf294a6871a1de2804 (patch)
treee766c7dd21ac1cda26d86ebff272502b53b2c57c /server/sonar-web
parent0479af2d115972ca1ed789f8018510ec9a00ff25 (diff)
downloadsonarqube-6cffa97b036ab628b91998cf294a6871a1de2804.tar.gz
sonarqube-6cffa97b036ab628b91998cf294a6871a1de2804.zip
SONAR-7690 support EVENTS.ANALYSIS_UUID in code
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb8
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb30
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb37
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb2
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb4
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb8
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/_versions.html.erb4
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb44
8 files changed, 59 insertions, 78 deletions
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb
index 7900407f219..4269dee6bb5 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb
@@ -190,11 +190,9 @@ class Api::EventsController < Api::ApiController
events = []
name = event.name
category = event.category
- snapshots = Snapshot.find(:all, :include => 'events', :conditions => ["(root_snapshot_id = ? OR id = ?) AND scope = 'PRJ'", event.snapshot_id, event.snapshot_id])
- snapshots.each do |snapshot|
- snapshot.events.reject {|e| e.name!=name || e.category!=category}.each do |event|
- events << event
- end
+ snapshot = Snapshot.find(:first, :include => 'events', :conditions => ["uuid = ? AND scope = 'PRJ'", event.analysis_uuid])
+ snapshot.events.reject {|e| e.name!=name || e.category!=category}.each do |event|
+ events << event
end
Event.transaction do
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb
index 8966df0f57a..f95fba9e7ee 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/comparison_controller.rb
@@ -39,13 +39,13 @@ class ComparisonController < ApplicationController
end
else
# the request comes from the comparison page: let's compare the given snapshots
- sids = get_params_as_array(:sids)
- unless sids.empty?
- selected_snapshots = Snapshot.all(:conditions => ['id in (?)', sids])
- # next loop is required to keep the order that was decided by the user and which comes from the "sids" parameter
- sids.each do |id|
+ suuids = get_params_as_array(:suuids)
+ unless suuids.empty?
+ selected_snapshots = Snapshot.all(:conditions => ['uuid in (?)', suuids])
+ # next loop is required to keep the order that was decided by the user and which comes from the "suuids" parameter
+ suuids.each do |uuid|
selected_snapshots.each do |s|
- snapshots << s if id==s.id.to_s
+ snapshots << s if uuid==s.uuid.to_s
end
end
end
@@ -69,20 +69,20 @@ class ComparisonController < ApplicationController
end
def versions
- key = params[:resource]
- sids = get_params_as_array(:sids)
+ id = params[:id]
+ suuids = get_params_as_array(:suuids)
- unless key.blank?
- resource = Project.by_key(params[:resource])
+ unless id.blank?
+ project = Project.by_key(id)
# we look for the events that are versions and that are not linked to snapshots already displayed on the page
- @versions = resource.events.select { |event| !event.snapshot_id.nil? && event.category==EventCategory::KEY_VERSION && !sids.include?(event.snapshot_id.to_s) }
+ @versions = project.events.select { |event| event.category==EventCategory::KEY_VERSION && !suuids.include?(event.analysis_uuid.to_s) }
# check if the latest snapshot if suggested or not (and if not, suggest it as "LATEST" => this is used for views or developers which do not have events)
- latest_snapshot_id = resource.last_snapshot.id
- current_and_suggested_sids = sids + @versions.map {|e| e.snapshot_id.to_s}
- unless current_and_suggested_sids.include?(latest_snapshot_id.to_s)
- @versions.unshift Event.new(:name => Api::Utils.message('comparison.version.latest'), :snapshot_id => latest_snapshot_id)
+ latest_snapshot_uuid = project.last_snapshot.uuid
+ current_and_suggested_suuids = suuids + @versions.map {|e| e.analysis_uuid.to_s}
+ unless current_and_suggested_suuids.include?(latest_snapshot_uuid.to_s)
+ @versions.unshift Event.new(:name => Api::Utils.message('comparison.version.latest'), :analysis_uuid => latest_snapshot_uuid)
end
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
index 0e020368855..6a8028e977f 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
@@ -301,7 +301,7 @@ class ProjectController < ApplicationController
if snapshot.event(EventCategory::KEY_VERSION)
# This is an update: we update the event
Event.update_all({:name => params[:version_name]},
- ["category = ? AND snapshot_id = ?", EventCategory::KEY_VERSION, snapshot.id])
+ ["category = ? AND analysis_uuid = ?", EventCategory::KEY_VERSION, snapshot.uuid])
flash[:notice] = message('project_history.version_updated', :params => h(params[:version_name]))
else
# We create an event on the snapshot
@@ -323,11 +323,8 @@ class ProjectController < ApplicationController
# We update all the related snapshots to have the same version as the next snapshot
next_snapshot = Snapshot.find(:first, :conditions => ['created_at>? and component_uuid=?', parent_snapshot.created_at.to_i*1000, parent_snapshot.component_uuid], :order => 'created_at asc')
- snapshots = find_project_snapshots(parent_snapshot.id)
- snapshots.each do |snapshot|
- snapshot.version = next_snapshot.version
- snapshot.save!
- end
+ parent_snapshot.version = next_snapshot.version
+ parent_snapshot.save!
# and we delete the events
event = parent_snapshot.event(EventCategory::KEY_VERSION)
@@ -352,15 +349,12 @@ class ProjectController < ApplicationController
if Event.already_exists(snapshot.component_uuid, params[:event_name], EventCategory::KEY_OTHER)
flash[:error] = message('project_history.event_already_exists', :params => h(params[:event_name]))
else
- snapshots = find_project_snapshots(snapshot.id)
- snapshots.each do |s|
- e = Event.new({:name => params[:event_name],
- :category => EventCategory::KEY_OTHER,
- :snapshot => s,
- :component_uuid => s.project.uuid,
- :event_date => s.created_at})
- e.save!
- end
+ e = Event.new({:name => params[:event_name],
+ :category => EventCategory::KEY_OTHER,
+ :snapshot => snapshot,
+ :component_uuid => snapshot.project.uuid,
+ :event_date => snapshot.created_at})
+ e.save!
flash[:notice] = message('project_history.event_created', :params => h(params[:event_name]))
end
@@ -413,20 +407,13 @@ class ProjectController < ApplicationController
project
end
- def find_project_snapshots(root_snapshot_id)
- Snapshot.find(:all, :include => ['events', 'project'], :conditions => ["(root_snapshot_id = ? OR id = ?) AND scope = 'PRJ'", root_snapshot_id, root_snapshot_id])
- end
-
- # Returns all an array that contains the given event + all the events that are the same, but which are attached on the submodules
+ # Returns all an array that contains the given event + all the events that are the same
def find_events(event)
events = []
name = event.name
category = event.category
- snapshots = find_project_snapshots(event.snapshot_id)
- snapshots.each do |snapshot|
- snapshot.events.reject { |e| e.name!=name || e.category!=category }.each do |event|
- events << event
- end
+ event.snapshot.events.reject { |e| e.name!=name || e.category!=category }.each do |event|
+ events << event
end
events
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb
index be3aa2eafa2..998a86db2ed 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb
@@ -24,7 +24,7 @@ class Event < ActiveRecord::Base
validates_length_of :category, :within => 1..50
belongs_to :resource, :class_name => 'Project', :foreign_key => 'component_uuid', :primary_key => 'uuid'
- belongs_to :snapshot
+ belongs_to :snapshot, :class_name => 'Snapshot', :foreign_key => 'analysis_uuid', :primary_key => 'uuid'
before_save :populate_snapshot
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb
index 90d1931ef84..1f008742a8e 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb
@@ -116,10 +116,6 @@ class Project < ActiveRecord::Base
end
end
- def events_with_snapshot
- events.select { |event| !event.snapshot_id.nil? }
- end
-
def key
kee
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb
index 535bc0e40b8..879ed2c648b 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb
@@ -29,7 +29,7 @@ class Snapshot < ActiveRecord::Base
has_many :measures, :class_name => 'ProjectMeasure', :conditions => 'person_id IS NULL'
has_many :person_measures, :class_name => 'ProjectMeasure', :conditions => 'person_id IS NOT NULL'
- has_many :events, :dependent => :destroy, :order => 'event_date DESC'
+ has_many :events, :class_name => 'Event', :foreign_key => 'analysis_uuid', :primary_key => 'uuid', :dependent => :destroy, :order => 'event_date DESC'
STATUS_UNPROCESSED = 'U'
STATUS_PROCESSED = 'P'
@@ -75,7 +75,7 @@ class Snapshot < ActiveRecord::Base
# 2. project B, which depends on A 1.0, is analyzed -> new snapshot A 1.0 with qualifier LIB.
# 3. project A has 2 snapshots : the first one with qualifier=TRK has measures, the second one with qualifier LIB has no measures. Its version must not be used in time machine
# That's why the 2 following SQL requests check the qualifiers (and optionally scopes, just to be sure)
- snapshots=Snapshot.find(:all, :conditions => ["snapshots.component_uuid=? AND events.snapshot_id=snapshots.id AND snapshots.status=? AND snapshots.scope=? AND snapshots.qualifier=?", resource.uuid, STATUS_PROCESSED, resource.scope, resource.qualifier],
+ snapshots=Snapshot.find(:all, :conditions => ["snapshots.component_uuid=? AND events.analysis_uuid=snapshots.uuid AND snapshots.status=? AND snapshots.scope=? AND snapshots.qualifier=?", resource.uuid, STATUS_PROCESSED, resource.scope, resource.qualifier],
:include => 'events',
:order => 'snapshots.created_at ASC')
@@ -112,7 +112,7 @@ class Snapshot < ActiveRecord::Base
# Look for the number_of_columns-2 last snapshots to display (they must have 'Version' events)
version_snapshots = []
if number_of_columns > 2
- snapshot_conditions[0] += " AND events.snapshot_id=snapshots.id AND events.category='Version' AND snapshots.id NOT IN (?)"
+ snapshot_conditions[0] += " AND events.analysis_uuid=snapshots.uuid AND events.category='Version' AND snapshots.id NOT IN (?)"
snapshot_conditions << [first_snapshot.id, last_snapshot.id]
version_snapshots=Snapshot.find(:all, :conditions => snapshot_conditions, :include => 'events', :order => 'snapshots.created_at ASC').last(number_of_columns-2)
end
@@ -153,7 +153,7 @@ class Snapshot < ActiveRecord::Base
def user_events
categories=EventCategory.categories(true)
category_names=categories.map { |cat| cat.name }
- Event.find(:all, :conditions => ["snapshot_id=? AND category IS NOT NULL", id], :order => 'event_date desc').select do |event|
+ Event.find(:all, :conditions => ["analysis_uuid=? AND category IS NOT NULL", uuid], :order => 'event_date desc').select do |event|
category_names.include?(event.category)
end
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/_versions.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/_versions.html.erb
index f2a3be5c321..7a5d7c80be5 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/_versions.html.erb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/_versions.html.erb
@@ -2,7 +2,7 @@
<option value=""></option>
<% @versions.each do |version| %>
- <option value="<%= version.snapshot_id -%>"><%= h version.name -%></option>
+ <option value="<%= version.analysis_uuid -%>"><%= h version.name -%></option>
<% end %>
-<% end %> \ No newline at end of file
+<% end %>
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb
index da6e94ccba4..dd67957720d 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/comparison/index.html.erb
@@ -20,20 +20,20 @@
}
function moveLeft(index) {
- sids = $j('#sids').val().split(',');
- idToLeft = sids[index];
- idToRight = sids[index - 1];
- sids.splice(index - 1, 2, [idToLeft, idToRight]);
- $j('#sids').val(sids.join(','));
+ suuids = $j('#suuids').val().split(',');
+ idToLeft = suuids[index];
+ idToRight = suuids[index - 1];
+ suuids.splice(index - 1, 2, [idToLeft, idToRight]);
+ $j('#suuids').val(suuids.join(','));
submitForm();
}
function moveRight(index) {
- sids = $j('#sids').val().split(',');
- idToRight = sids[index];
- idToLeft = sids[index + 1];
- sids.splice(index, 2, [idToLeft, idToRight]);
- $j('#sids').val(sids.join(','));
+ suuids = $j('#suuids').val().split(',');
+ idToRight = suuids[index];
+ idToLeft = suuids[index + 1];
+ suuids.splice(index, 2, [idToLeft, idToRight]);
+ $j('#suuids').val(suuids.join(','));
submitForm();
}
@@ -70,7 +70,7 @@
<h1 class="page-title"><%= h message('comparison.page') -%></h1>
</header>
<form method="GET" id="compare-form" action="<%= ApplicationController.root_context -%>/comparison/index">
- <input type="hidden" name="sids" id="sids" value="<%= @snapshots.map { |s| s.id.to_s }.join(',') -%>">
+ <input type="hidden" name="suuids" id="suuids" value="<%= @snapshots.map { |s| s.uuid.to_s }.join(',') -%>">
<input type="hidden" name="metrics" id="metrics" value="<%= @metrics.map { |m| m.key }.join(',') -%>">
<div style="margin-bottom: 4px">
@@ -112,9 +112,9 @@
$j('#version_loading').show();
$j.ajax({
type:'GET',
- url:'<%= ApplicationController.root_context -%>/comparison/versions?resource='
- + id + '&sids='
- + $j('#sids').val(),
+ url:'<%= ApplicationController.root_context -%>/comparison/versions?id='
+ + id + '&suuids='
+ + $j('#suuids').val(),
success:function (data) {
$j('#new_version').html(data);
$j('#new_version').select2({
@@ -140,14 +140,14 @@
</select>
<script>
$j('#new_version').change(function (event) {
- var id = event.target.value;
- if (id != null) {
- var currentSnapshotIds = $j('#sids').val();
- if (currentSnapshotIds.length > 0) {
- currentSnapshotIds += ',';
+ var uuid = event.target.value;
+ if (uuid != null) {
+ var currentSnapshotUuids = $j('#suuids').val();
+ if (currentSnapshotUuids.length > 0) {
+ currentSnapshotUuids += ',';
}
- currentSnapshotIds += id;
- $j('#sids').val(currentSnapshotIds);
+ currentSnapshotUuids += uuid;
+ $j('#suuids').val(currentSnapshotUuids);
$j('#compare-form').submit();
}
});
@@ -177,7 +177,7 @@
</td>
<td style="text-align: center; min-width: 100px">
<div style="width: 100%; text-align: center;">
- <a class="icon-delete" href="#" onclick="removeFromList(<%= index -%>, $j('#sids'))" id="del-r-<%= index -%>" title="<%= message('comparison.suppress_column') -%>"></a>
+ <a class="icon-delete" href="#" onclick="removeFromList(<%= index -%>, $j('#suuids'))" id="del-r-<%= index -%>" title="<%= message('comparison.suppress_column') -%>"></a>
</div>
</td>
<td style="vertical-align: bottom;">