aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-10-26 11:00:45 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-10-26 11:00:45 +0200
commit48563f868573a21cac93c8143b36b26200f19a6c (patch)
treeb068f8641b1b125baf54d49ea3023de9117b1e26
parent95dfe333644a75628ac2e47b62470a0a789f622e (diff)
downloadsonarqube-48563f868573a21cac93c8143b36b26200f19a6c.tar.gz
sonarqube-48563f868573a21cac93c8143b36b26200f19a6c.zip
SONAR-2919 Fix issues on the event handling
- Make it impossible to create event without a category -> created "Other" category -> updated both UI and WS (actually: constraint on Event class) - Fix display issue on Chrome - Make it impossible to remove version from last snapshot - Show event widget on sub-projects - Update purge mechanism to delete events that are not attached to a snapshot or attached to an unexisting snapshot
-rw-r--r--plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java14
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans-result.xml21
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans.xml15
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties1
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb14
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/event.rb3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/event_category.rb12
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/project/_edit_event.html.erb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/project/events.html.erb3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb2
11 files changed, 66 insertions, 23 deletions
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb
index 1a2755b5af5..c9fb693c91f 100644
--- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb
+++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb
@@ -1,4 +1,4 @@
-<% if @project.project? %>
+<% if @project.scope=='PRJ' %>
<div id="widget_events"><div id="events_portlet"></div></div>
<script>
<%= remote_function(:update => "events_portlet", :url => { :controller => :project, :action => :events, :id => @snapshot.id }, :method => 'get') %>
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java
index 41ddd5e06d6..84f4ab14de1 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java
@@ -22,6 +22,8 @@ package org.sonar.plugins.dbcleaner.purges;
import org.sonar.api.batch.Event;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.database.model.SnapshotSource;
import org.sonar.plugins.dbcleaner.api.Purge;
import org.sonar.plugins.dbcleaner.api.PurgeContext;
import org.sonar.plugins.dbcleaner.api.PurgeUtils;
@@ -37,8 +39,16 @@ public final class PurgeEventOrphans extends Purge {
}
public void purge(PurgeContext context) {
- Query query = getSession().createQuery("SELECT e.id FROM " + Event.class.getSimpleName() +
- " e WHERE e.resourceId IS NOT NULL AND NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=e.resourceId)");
+ String selectEventsSql = "SELECT e.id FROM " + Event.class.getSimpleName() + " e WHERE (";
+ selectEventsSql += "e.resourceId IS NOT NULL AND NOT EXISTS(FROM " + ResourceModel.class.getSimpleName()
+ + " r WHERE r.id=e.resourceId)";
+ selectEventsSql += ") OR (";
+ selectEventsSql += "e.snapshot IS NULL";
+ selectEventsSql += ") OR (";
+ selectEventsSql += "e.snapshot IS NOT NULL AND NOT EXISTS(FROM " + Snapshot.class.getSimpleName() + " s WHERE s.id=e.snapshot)";
+ selectEventsSql += ")";
+
+ Query query = getSession().createQuery(selectEventsSql);
final List<Integer> eventIds = query.getResultList();
PurgeUtils.executeQuery(getSession(), "", eventIds, "DELETE FROM " + Event.class.getSimpleName() + " WHERE id in (:ids)");
}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans-result.xml
index 14c4f413a35..b518b72352d 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans-result.xml
@@ -4,13 +4,24 @@
description="[null]"
enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
- <!-- global event -->
- <events id="1" name="Upgrade" resource_id="[null]" snapshot_id="[null]" category="SYSTEM" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]" />
+ <snapshots id="1" project_id="1" scope="FIL" qualifier="TRK" created_at="2008-12-02 13:58:00.00"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]" depth="[null]" version="[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]" />
- <!-- project event -->
- <events id="2" name="Version 1.0" resource_id="1" snapshot_id="[null]" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/>
+ <!-- orphan : global event, attached to nothing (old way to create events) -->
+ <!--events id="1" name="Upgrade" resource_id="[null]" snapshot_id="[null]" category="SYSTEM" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/-->
+
+ <!-- orphan : project event, attached to a resource but with no snapshot (old way to create events) -->
+ <!--events id="2" name="Version 1.0" resource_id="1" snapshot_id="[null]" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/-->
<!-- orphan : the project does not exist-->
- <!--<events id="3" name="Version 0.9" resource_id="5" snapshot_id="[null]" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/> -->
+ <!--events id="3" name="Version 0.9" resource_id="5" snapshot_id="[null]" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/-->
+
+ <!-- orphan : the resource exists but not the snapshot -->
+ <!--events id="4" name="Version 1.0" resource_id="1" snapshot_id="2" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/-->
+
+ <!-- "correct" event that is attached to an existing resource and existing snapshot -->
+ <events id="5" name="Version 1.0" resource_id="1" snapshot_id="1" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/>
</dataset> \ No newline at end of file
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans.xml
index a552039b419..1462e72d525 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans.xml
@@ -4,13 +4,24 @@
description="[null]"
enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
- <!-- global event -->
+ <snapshots id="1" project_id="1" scope="FIL" qualifier="TRK" created_at="2008-12-02 13:58:00.00"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]" depth="[null]" version="[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]" />
+
+ <!-- orphan : global event, attached to nothing (old way to create events) -->
<events id="1" name="Upgrade" resource_id="[null]" snapshot_id="[null]" category="SYSTEM" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/>
- <!-- project event -->
+ <!-- orphan : project event, attached to a resource but with no snapshot (old way to create events) -->
<events id="2" name="Version 1.0" resource_id="1" snapshot_id="[null]" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/>
<!-- orphan : the project does not exist-->
<events id="3" name="Version 0.9" resource_id="5" snapshot_id="[null]" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/>
+ <!-- orphan : the resource exists but not the snapshot -->
+ <events id="4" name="Version 1.0" resource_id="1" snapshot_id="2" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/>
+
+ <!-- "correct" event that is attached to an existing resource and existing snapshot -->
+ <events id="5" name="Version 1.0" resource_id="1" snapshot_id="1" category="VERSION" description="[null]" event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]"/>
+
</dataset> \ No newline at end of file
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
index a39c365c22d..54ae0a501c8 100644
--- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
@@ -233,6 +233,7 @@ project_links.scm_dev=Developer connection
event.category.Version=Version
event.category.Alert=Alert
event.category.Profile=Profile
+event.category.Other=Other
#------------------------------------------------------------------------------
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
index b36c5004c47..2b43fb6d8c1 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
@@ -229,7 +229,8 @@ class ProjectController < ApplicationController
return access_denied unless is_admin?(snapshot)
@event = Event.new(:snapshot => snapshot, :resource => snapshot.resource)
- @categories=EventCategory.categories
+ @categories=EventCategory.categories(false)
+ @categories << EventCategory.other_category
render :partial => 'edit_event'
end
@@ -253,7 +254,8 @@ class ProjectController < ApplicationController
@event = Event.find(params[:id])
return access_denied unless is_admin?(@event.resource)
- @categories=EventCategory.categories
+ @categories=EventCategory.categories(false)
+ @categories << EventCategory.other_category
render :partial => 'edit_event'
end
@@ -262,10 +264,10 @@ class ProjectController < ApplicationController
return access_denied unless is_admin?(event.resource)
events = find_events(event)
- events.each do |event|
- event.name = params[:event][:name]
- event.category = params[:event][:category]
- event.save!
+ events.each do |e|
+ e.name = params[:event][:name]
+ e.category = params[:event][:category]
+ e.save!
end
flash[:notice] = message('project_history.event_updated')
redirect_to :action => 'history', :id => event.resource_id
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/event.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/event.rb
index 0334e58351a..c1fdea77392 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/event.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/event.rb
@@ -20,7 +20,8 @@
class Event < ActiveRecord::Base
validates_presence_of :event_date
- validates_length_of :name, :within => 1..50
+ validates_length_of :name, :within => 1..400
+ validates_length_of :category, :within => 1..50
belongs_to :resource, :class_name => 'Project', :foreign_key => 'resource_id'
belongs_to :snapshot
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/event_category.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/event_category.rb
index 89e957bc7df..964954ee844 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/event_category.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/event_category.rb
@@ -24,6 +24,7 @@ class EventCategory
KEY_VERSION='Version'
KEY_ALERT='Alert'
KEY_PROFILE='Profile'
+ KEY_OTHER='Other'
def initialize(name=nil, description=nil)
@name=name
@@ -81,17 +82,22 @@ class EventCategory
end
def editable?
- !([KEY_VERSION, KEY_ALERT, KEY_PROFILE].include?(name))
+ !([KEY_VERSION, KEY_ALERT, KEY_PROFILE, KEY_OTHER].include?(name))
end
def self.defaults
- [
+ @@defaults ||= [
EventCategory.new(KEY_VERSION, 'Application version'),
EventCategory.new(KEY_ALERT, 'Alert'),
- EventCategory.new(KEY_PROFILE, 'Profile change')
+ EventCategory.new(KEY_PROFILE, 'Profile change'),
+ EventCategory.new(KEY_OTHER, 'Other events')
]
end
+ def self.other_category
+ self.defaults[3]
+ end
+
def self.categories(include_defaults=false)
events= (include_defaults ? defaults : [])
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/_edit_event.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/_edit_event.html.erb
index 5f47962d0b5..e2da29e7f3c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/project/_edit_event.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/_edit_event.html.erb
@@ -13,7 +13,7 @@
</td>
<td class="left" nowrap="nowrap" valign="top">
<span class="comments"><%= message('category') -%> (<%= link_to message('configure').downcase, {:controller=> 'event_categories', :action => 'index'}, :class => 'action' %>)</span><br>
- <%= f.select(:category, @categories.collect {|c| [ message('event.category.' + c.name, :default => c.name), c.name ] }, {:include_blank => true}) %>
+ <%= f.select(:category, @categories.collect {|c| [ message('event.category.' + c.name, :default => c.name), c.name ] }) %>
</td>
</tr>
<tr>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/events.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/events.html.erb
index 4a51df882ef..17233b3f8c1 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/project/events.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/events.html.erb
@@ -10,7 +10,7 @@
<table id="events" class="spaced data">
<thead>
<tr>
- <th colspan="5">
+ <th colspan="4">
</th>
</tr>
</thead>
@@ -44,3 +44,4 @@
<% if index>=max_rows %>
<a href="#" onclick="$('all_events').show();$('show_more_events').hide()" id="show_more_events" class="action"><%= message('show_more') -%></a>
<% end %>
+
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb
index 7f1d2d3e769..27b81b311df 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb
@@ -63,7 +63,7 @@
<td class="max-width"><%= version_event.name if version_event -%></td>
<td class="small" style="padding-left:20px">
<a href="#" onclick="$('version_<%= snapshot.id -%>').hide();$('version_<%= snapshot.id -%>_form').show();"><%= version_event ? message('project_history.rename_version') : message('project_history.create_version') -%></a>
- <% if version_event %>
+ <% if version_event && !snapshot.islast? %>
<%= link_to ( message('project_history.remove_version'),
{ :action => 'delete_version', :sid => snapshot.id},
:confirm => message('project_history.do_you_want_to_remove_version', :params => version_event.name) ) -%>