diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2011-10-26 11:00:45 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2011-10-26 11:00:45 +0200 |
commit | 48563f868573a21cac93c8143b36b26200f19a6c (patch) | |
tree | b068f8641b1b125baf54d49ea3023de9117b1e26 /plugins/sonar-dbcleaner-plugin | |
parent | 95dfe333644a75628ac2e47b62470a0a789f622e (diff) | |
download | sonarqube-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
Diffstat (limited to 'plugins/sonar-dbcleaner-plugin')
3 files changed, 41 insertions, 9 deletions
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 |