aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-core-plugin
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-07-27 18:16:16 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-07-27 20:59:45 +0400
commita24cd25f9ca3062d601164c2d0c38c0c1aa919b4 (patch)
tree01fc0540b5b8cd142dfc736978005f460be961e2 /plugins/sonar-core-plugin
parent79e08b37ee316ccd238e272aabb5313cee60bc00 (diff)
downloadsonarqube-a24cd25f9ca3062d601164c2d0c38c0c1aa919b4.tar.gz
sonarqube-a24cd25f9ca3062d601164c2d0c38c0c1aa919b4.zip
SONAR-2607 Show in notification: project, resource and title of review
Diffstat (limited to 'plugins/sonar-core-plugin')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java42
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest.java10
2 files changed, 30 insertions, 22 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java
index 6e17f67f66d..529c42dd29a 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java
@@ -49,12 +49,14 @@ public class CloseReviewsDecorator implements Decorator {
private static final Logger LOG = LoggerFactory.getLogger(CloseReviewsDecorator.class);
+ private Project project;
private ResourcePersister resourcePersister;
private DatabaseSession databaseSession;
private NotificationManager notificationManager;
private UserFinder userFinder;
- public CloseReviewsDecorator(ResourcePersister resourcePersister, DatabaseSession databaseSession, NotificationManager notificationManager, UserFinder userFinder) {
+ public CloseReviewsDecorator(Project project, ResourcePersister resourcePersister, DatabaseSession databaseSession, NotificationManager notificationManager, UserFinder userFinder) {
+ this.project = project;
this.resourcePersister = resourcePersister;
this.databaseSession = databaseSession;
this.notificationManager = notificationManager;
@@ -71,8 +73,8 @@ public class CloseReviewsDecorator implements Decorator {
int resourceId = currentSnapshot.getResourceId();
int snapshotId = currentSnapshot.getId();
- closeReviews(resourceId, snapshotId);
- reopenReviews(resourceId);
+ closeReviews(resource, resourceId, snapshotId);
+ reopenReviews(resource, resourceId);
if (ResourceUtils.isRootProject(resource)) {
closeReviewsForDeletedResources(resourceId, currentSnapshot.getId());
}
@@ -84,13 +86,13 @@ public class CloseReviewsDecorator implements Decorator {
/**
* Close reviews for which violations have been fixed.
*/
- protected int closeReviews(int resourceId, int snapshotId) {
+ protected int closeReviews(Resource resource, int resourceId, int snapshotId) {
String conditions = " WHERE status!='CLOSED' AND resource_id=" + resourceId
+ " AND rule_failure_permanent_id NOT IN " + "(SELECT permanent_id FROM rule_failures WHERE snapshot_id=" + snapshotId
+ " AND permanent_id IS NOT NULL)";
List<Review> reviews = databaseSession.getEntityManager().createNativeQuery("SELECT * FROM reviews " + conditions, Review.class).getResultList();
for (Review review : reviews) {
- notifyClosed(review);
+ notifyClosed(resource, review);
}
int rowUpdated = databaseSession.createNativeQuery("UPDATE reviews SET status='CLOSED', updated_at=CURRENT_TIMESTAMP" + conditions).executeUpdate();
LOG.debug("- {} reviews set to 'closed' on resource #{}", rowUpdated, resourceId);
@@ -100,11 +102,11 @@ public class CloseReviewsDecorator implements Decorator {
/**
* Reopen reviews that had been set to resolved but for which the violation is still here.
*/
- protected int reopenReviews(int resourceId) {
+ protected int reopenReviews(Resource resource, int resourceId) {
String conditions = " WHERE status='RESOLVED' AND resource_id=" + resourceId;
List<Review> reviews = databaseSession.getEntityManager().createNativeQuery("SELECT * FROM reviews " + conditions, Review.class).getResultList();
for (Review review : reviews) {
- notifyReopened(review);
+ notifyReopened(resource, review);
}
int rowUpdated = databaseSession.createNativeQuery("UPDATE reviews SET status='REOPENED', resolution=NULL, updated_at=CURRENT_TIMESTAMP" + conditions).executeUpdate();
LOG.debug("- {} reviews set to 'reopened' on resource #{}", rowUpdated, resourceId);
@@ -123,7 +125,7 @@ public class CloseReviewsDecorator implements Decorator {
.setParameter(1, Boolean.TRUE)
.getResultList();
for (Review review : reviews) {
- notifyClosed(review);
+ notifyClosed(null, review);
}
int rowUpdated = databaseSession.createNativeQuery("UPDATE reviews SET status='CLOSED', updated_at=CURRENT_TIMESTAMP" + conditions)
.setParameter(1, Boolean.TRUE)
@@ -148,11 +150,8 @@ public class CloseReviewsDecorator implements Decorator {
return user != null ? user.getLogin() : null;
}
- void notifyReopened(Review review) {
- Notification notification = new Notification("review-changed")
- .setFieldValue("reviewId", String.valueOf(review.getId()))
- .setFieldValue("creator", getCreator(review))
- .setFieldValue("assignee", getAssignee(review))
+ void notifyReopened(Resource resource, Review review) {
+ Notification notification = createReviewNotification(resource, review)
.setFieldValue("old.status", review.getStatus())
.setFieldValue("new.status", "REOPENED")
.setFieldValue("old.resolution", review.getResolution())
@@ -160,14 +159,21 @@ public class CloseReviewsDecorator implements Decorator {
notificationManager.scheduleForSending(notification);
}
- void notifyClosed(Review review) {
- Notification notification = new Notification("review-changed")
- .setFieldValue("reviewId", String.valueOf(review.getId()))
- .setFieldValue("creator", getCreator(review))
- .setFieldValue("assignee", getAssignee(review))
+ void notifyClosed(Resource resource, Review review) {
+ Notification notification = createReviewNotification(resource, review)
.setFieldValue("old.status", review.getStatus())
.setFieldValue("new.status", "CLOSED");
notificationManager.scheduleForSending(notification);
}
+ private Notification createReviewNotification(Resource resource, Review review) {
+ return new Notification("review-changed")
+ .setFieldValue("reviewId", String.valueOf(review.getId()))
+ .setFieldValue("project", project.getRoot().getLongName())
+ .setFieldValue("resource", resource != null ? resource.getLongName() : null)
+ .setFieldValue("title", review.getTitle())
+ .setFieldValue("creator", getCreator(review))
+ .setFieldValue("assignee", getAssignee(review));
+ }
+
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest.java
index 19c04f675c8..afab33e4d78 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest.java
@@ -45,8 +45,10 @@ public class CloseReviewsDecoratorTest extends AbstractDbUnitTestCase {
@Before
public void setUp() {
+ Project project = mock(Project.class);
+ when(project.getRoot()).thenReturn(project);
notificationManager = mock(NotificationManager.class);
- reviewsDecorator = new CloseReviewsDecorator(null, getSession(), notificationManager, mock(UserFinder.class));
+ reviewsDecorator = new CloseReviewsDecorator(project, null, getSession(), notificationManager, mock(UserFinder.class));
}
@Test
@@ -60,7 +62,7 @@ public class CloseReviewsDecoratorTest extends AbstractDbUnitTestCase {
public void shouldCloseReviewWithoutCorrespondingViolation() throws Exception {
setupData("fixture");
- int count = reviewsDecorator.closeReviews(666, 222);
+ int count = reviewsDecorator.closeReviews(null, 666, 222);
assertThat(count, is(3));
verify(notificationManager, times(3)).scheduleForSending(any(Notification.class));
@@ -79,10 +81,10 @@ public class CloseReviewsDecoratorTest extends AbstractDbUnitTestCase {
setupData("fixture");
// First we close the reviews for which the violations have been fixed (this is because we use the same "fixture"...)
- reviewsDecorator.closeReviews(666, 222);
+ reviewsDecorator.closeReviews(null, 666, 222);
// And now we reopen the reviews that still have a violation
- int count = reviewsDecorator.reopenReviews(666);
+ int count = reviewsDecorator.reopenReviews(null, 666);
assertThat(count, is(1));
verify(notificationManager, times(4)).scheduleForSending(any(Notification.class));