From: Sébastien Lesaint Date: Wed, 22 Jun 2016 09:16:09 +0000 (+0200) Subject: SONAR-7690 support EVENTS.ANALYSIS_UUID in code X-Git-Tag: 6.0-RC1~253 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6cffa97b036ab628b91998cf294a6871a1de2804;p=sonarqube.git SONAR-7690 support EVENTS.ANALYSIS_UUID in code --- diff --git a/it/it-tests/src/test/resources/measureHistory/HistoryUiTest/history-timeline-widget/should-display-even-if-one-missing-metric.html b/it/it-tests/src/test/resources/measureHistory/HistoryUiTest/history-timeline-widget/should-display-even-if-one-missing-metric.html index 44615acc462..81030e50455 100644 --- a/it/it-tests/src/test/resources/measureHistory/HistoryUiTest/history-timeline-widget/should-display-even-if-one-missing-metric.html +++ b/it/it-tests/src/test/resources/measureHistory/HistoryUiTest/history-timeline-widget/should-display-even-if-one-missing-metric.html @@ -10,10 +10,10 @@ timeline - + open - /widget?id=timeline&resource=sample&metric1=complexity&metric2=commits - + /widget?id=timeline&resource=sample&metric1=complexity&metric2=commits + assertElementPresent diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java index 0a952701b9d..08eca3e5205 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java @@ -29,7 +29,6 @@ import org.sonar.server.computation.analysis.AnalysisMetadataHolder; import org.sonar.server.computation.component.Component; import org.sonar.server.computation.component.ComponentVisitor; import org.sonar.server.computation.component.CrawlerDepthLimit; -import org.sonar.server.computation.component.DbIdsRepository; import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; import org.sonar.server.computation.component.TreeRootHolder; import org.sonar.server.computation.component.TypeAwareVisitorAdapter; @@ -45,16 +44,14 @@ public class PersistEventsStep implements ComputationStep { private final AnalysisMetadataHolder analysisMetadataHolder; private final TreeRootHolder treeRootHolder; private final EventRepository eventRepository; - private final DbIdsRepository dbIdsRepository; public PersistEventsStep(DbClient dbClient, System2 system2, TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder, - EventRepository eventRepository, DbIdsRepository dbIdsRepository) { + EventRepository eventRepository) { this.dbClient = dbClient; this.system2 = system2; this.treeRootHolder = treeRootHolder; this.analysisMetadataHolder = analysisMetadataHolder; this.eventRepository = eventRepository; - this.dbIdsRepository = dbIdsRepository; } @Override @@ -102,8 +99,8 @@ public class PersistEventsStep implements ComputationStep { private EventDto newBaseEvent(Component component, Long analysisDate) { return new EventDto() + .setAnalysisUuid(analysisMetadataHolder.getUuid()) .setComponentUuid(component.getUuid()) - .setSnapshotId(dbIdsRepository.getSnapshotId(component)) .setCreatedAt(system2.now()) .setDate(analysisDate); } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/dashboard/widget/timeline.html.erb b/server/sonar-server/src/main/resources/org/sonar/server/dashboard/widget/timeline.html.erb index f9755436f66..e50edc58436 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/dashboard/widget/timeline.html.erb +++ b/server/sonar-server/src/main/resources/org/sonar/server/dashboard/widget/timeline.html.erb @@ -132,7 +132,7 @@ from_date = first_date if !from_date || from_date > first_date end end - Event.find(:all, :conditions => ["component_uuid=? AND event_date>=?", @resource.uuid, from_date.to_i*1000], :order => 'event_date').each() do |event| + Event.find(:all, :conditions => ["component_uuid=? AND event_date>=?", @resource.uuid, from_date.to_i*1000], :order => 'event_date', :include => 'snapshot').each() do |event| if events[event.event_date] events[event.event_date] << event else @@ -144,7 +144,7 @@ events.keys().sort.each() do |e_date| e_details = events[e_date] js_events += "{sid:" - js_events += e_details[0].snapshot_id.to_s + js_events += e_details[0].snapshot.id.to_s js_events += ",d:d(" js_events += e_date.year.to_s js_events += "," diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java index 89cd11586d8..ce26f3c8075 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java @@ -30,7 +30,6 @@ import org.sonar.db.DbTester; import org.sonar.server.computation.analysis.AnalysisMetadataHolderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; -import org.sonar.server.computation.component.DbIdsRepositoryImpl; import org.sonar.server.computation.component.ReportComponent; import org.sonar.server.computation.event.Event; import org.sonar.server.computation.event.EventRepository; @@ -61,6 +60,7 @@ public class PersistEventsStepTest extends BaseStepTest { .build()) .build()) .build(); + private static final String ANALYSIS_UUID = "uuid_1"; System2 system2 = mock(System2.class); @@ -73,16 +73,14 @@ public class PersistEventsStepTest extends BaseStepTest { private Date someDate = new Date(150000000L); - DbIdsRepositoryImpl dbIdsRepository = new DbIdsRepositoryImpl(); - EventRepository eventRepository = mock(EventRepository.class); PersistEventsStep step; @Before public void setup() { when(system2.now()).thenReturn(1225630680000L); - analysisMetadataHolder.setAnalysisDate(someDate.getTime()); - step = new PersistEventsStep(dbTester.getDbClient(), system2, treeRootHolder, analysisMetadataHolder, eventRepository, dbIdsRepository); + analysisMetadataHolder.setAnalysisDate(someDate.getTime()).setUuid(ANALYSIS_UUID); + step = new PersistEventsStep(dbTester.getDbClient(), system2, treeRootHolder, analysisMetadataHolder, eventRepository); when(eventRepository.getEvents(any(Component.class))).thenReturn(Collections.emptyList()); } @@ -108,8 +106,6 @@ public class PersistEventsStepTest extends BaseStepTest { treeRootHolder.setRoot(ROOT); - dbIdsRepository.setSnapshotId(ROOT, 1000L); - when(eventRepository.getEvents(ROOT)).thenReturn(ImmutableList.of(Event.createAlert("Red (was Orange)", null, "Open issues > 0"))); treeRootHolder.setRoot(ROOT); @@ -139,7 +135,6 @@ public class PersistEventsStepTest extends BaseStepTest { .build()) .build(); treeRootHolder.setRoot(project); - dbIdsRepository.setSnapshotId(ROOT, 1000L); step.execute(); @@ -167,7 +162,6 @@ public class PersistEventsStepTest extends BaseStepTest { .build()) .build(); treeRootHolder.setRoot(project); - dbIdsRepository.setSnapshotId(ROOT, 1001L); step.execute(); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml index b6239415365..73af5e041c0 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml @@ -1,43 +1,132 @@ - + + purge_status="[null]" + period1_mode="[null]" + period1_param="[null]" + period1_date="[null]" + period2_mode="[null]" + period2_param="[null]" + period2_date="[null]" + period3_mode="[null]" + period3_param="[null]" + period3_date="[null]" + period4_mode="[null]" + period4_param="[null]" + period4_date="[null]" + period5_mode="[null]" + period5_param="[null]" + period5_date="[null]" + component_uuid="ABCD" + parent_snapshot_id="[null]" + root_component_uuid="ABCD" + root_snapshot_id="[null]" + scope="PRJ" + qualifier="TRK" + created_at="1226379600000" + build_date="1226379600000" + version="0.9" + path="" + status="P" + islast="[false]" + depth="0"/> + purge_status="[null]" + period1_mode="[null]" + period1_param="[null]" + period1_date="[null]" + period2_mode="[null]" + period2_param="[null]" + period2_date="[null]" + period3_mode="[null]" + period3_param="[null]" + period3_date="[null]" + period4_mode="[null]" + period4_param="[null]" + period4_date="[null]" + period5_mode="[null]" + period5_param="[null]" + period5_date="[null]" + component_uuid="ABCD" + parent_snapshot_id="[null]" + root_component_uuid="ABCD" + root_snapshot_id="[null]" + scope="PRJ" + qualifier="TRK" + created_at="1226494680000" + build_date="1226494680000" + version="1.0" + path="" + status="P" + islast="[false]" + depth="0"/> + purge_status="[null]" + period1_mode="[null]" + period1_param="[null]" + period1_date="[null]" + period2_mode="[null]" + period2_param="[null]" + period2_date="[null]" + period3_mode="[null]" + period3_param="[null]" + period3_date="[null]" + period4_mode="[null]" + period4_param="[null]" + period4_date="[null]" + period5_mode="[null]" + period5_param="[null]" + period5_date="[null]" + component_uuid="ABCD" + parent_snapshot_id="[null]" + root_component_uuid="ABCD" + root_snapshot_id="[null]" + scope="PRJ" + qualifier="TRK" + created_at="1227157200000" + build_date="1227157200000" + version="1.1" + path="" + status="P" + islast="[false]" + depth="0"/> - + - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml index 0484c25b2b7..ceaa3476468 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml @@ -1,62 +1,207 @@ - + + purge_status="[null]" + period1_mode="[null]" + period1_param="[null]" + period1_date="[null]" + period2_mode="[null]" + period2_param="[null]" + period2_date="[null]" + period3_mode="[null]" + period3_param="[null]" + period3_date="[null]" + period4_mode="[null]" + period4_param="[null]" + period4_date="[null]" + period5_mode="[null]" + period5_param="[null]" + period5_date="[null]" + component_uuid="ABCD" + parent_snapshot_id="[null]" + root_component_uuid="ABCD" + root_snapshot_id="[null]" + scope="PRJ" + qualifier="TRK" + created_at="1226379600000" + build_date="1226379600000" + version="0.9" + path="" + status="P" + islast="[false]" + depth="0"/> + purge_status="[null]" + period1_mode="[null]" + period1_param="[null]" + period1_date="[null]" + period2_mode="[null]" + period2_param="[null]" + period2_date="[null]" + period3_mode="[null]" + period3_param="[null]" + period3_date="[null]" + period4_mode="[null]" + period4_param="[null]" + period4_date="[null]" + period5_mode="[null]" + period5_param="[null]" + period5_date="[null]" + component_uuid="ABCD" + parent_snapshot_id="[null]" + root_component_uuid="ABCD" + root_snapshot_id="[null]" + scope="PRJ" + qualifier="TRK" + created_at="1226494680000" + build_date="1226494680000" + version="1.0" + path="" + status="P" + islast="[false]" + depth="0"/> + purge_status="[null]" + period1_mode="[null]" + period1_param="[null]" + period1_date="[null]" + period2_mode="[null]" + period2_param="[null]" + period2_date="[null]" + period3_mode="[null]" + period3_param="[null]" + period3_date="[null]" + period4_mode="[null]" + period4_param="[null]" + period4_date="[null]" + period5_mode="[null]" + period5_param="[null]" + period5_date="[null]" + component_uuid="ABCD" + parent_snapshot_id="[null]" + root_component_uuid="ABCD" + root_snapshot_id="[null]" + scope="PRJ" + qualifier="TRK" + created_at="1227157200000" + build_date="1227157200000" + version="1.1" + path="" + status="P" + islast="[false]" + depth="0"/> + purge_status="[null]" + period1_mode="[null]" + period1_param="[null]" + period1_date="[null]" + period2_mode="[null]" + period2_param="[null]" + period2_date="[null]" + period3_mode="[null]" + period3_param="[null]" + period3_date="[null]" + period4_mode="[null]" + period4_param="[null]" + period4_date="[null]" + period5_mode="[null]" + period5_param="[null]" + period5_date="[null]" + component_uuid="ABCD" + parent_snapshot_id="[null]" + root_component_uuid="ABCD" + root_snapshot_id="[null]" + scope="PRJ" + qualifier="TRK" + created_at="1227358680000" + build_date="1227358680000" + version="1.1" + path="" + status="P" + islast="[false]" + depth="0"/> + purge_status="[null]" + period1_mode="[null]" + period1_param="[null]" + period1_date="[null]" + period2_mode="[null]" + period2_param="[null]" + period2_date="[null]" + period3_mode="[null]" + period3_param="[null]" + period3_date="[null]" + period4_mode="[null]" + period4_param="[null]" + period4_date="[null]" + period5_mode="[null]" + period5_param="[null]" + period5_date="[null]" + component_uuid="ABCD" + parent_snapshot_id="[null]" + root_component_uuid="ABCD" + root_snapshot_id="[null]" + scope="PRJ" + qualifier="TRK" + created_at="1227934800000" + build_date="1227934800000" + version="1.1" + path="" + status="P" + islast="[true]" + depth="0"/> - - - + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_version_event-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_version_event-result.xml index 1b72b63d5e7..08c70eb07cb 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_version_event-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_version_event-result.xml @@ -1,13 +1,13 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version-result.xml index 2a56e0c7203..7b1e1b13577 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version-result.xml @@ -1,14 +1,35 @@ - - + + - + - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version.xml index 93bfc6001b8..e49dd98d343 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version.xml @@ -1,31 +1,31 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/nothing_to_do_when_no_events_in_report.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/nothing_to_do_when_no_events_in_report.xml index 0d9badce82d..df246ef8e1a 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/nothing_to_do_when_no_events_in_report.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/nothing_to_do_when_no_events_in_report.xml @@ -1,41 +1,41 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/persist_report_events_with_component_children-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/persist_report_events_with_component_children-result.xml index 9eba6a21ee8..efbe7119b96 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/persist_report_events_with_component_children-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/persist_report_events_with_component_children-result.xml @@ -1,13 +1,13 @@ 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 @@ <% @versions.each do |version| %> - + <% 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 @@

<%= h message('comparison.page') -%>

- +
@@ -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 @@