import org.sonar.core.review.ReviewDto;
import org.sonar.core.review.ReviewMapper;
import org.sonar.core.review.workflow.review.Comment;
+import org.sonar.core.review.workflow.review.DefaultReview;
import org.sonar.core.review.workflow.review.MutableReview;
import java.util.Date;
this.mybatis = mb;
}
- public void store(MutableReview review) {
+ public void store(DefaultReview review) {
store(review, new Date());
}
@VisibleForTesting
- void store(MutableReview review, Date now) {
+ void store(DefaultReview review, Date now) {
if (review.getReviewId() == null) {
LOG.error("Review has no id. Violation id is: " + review.getViolationId());
return;
ReviewDto dto = mapper.findById(review.getReviewId());
dto.setResolution(review.getResolution());
dto.setStatus(review.getStatus());
- dto.setAssigneeId(review.getAssigneeId());
dto.setData(KeyValueFormat.format(review.getProperties()));
dto.setUpdatedAt(now);
mapper.update(dto);
package org.sonar.core.review.workflow;
import org.sonar.api.config.Settings;
+import org.sonar.core.review.workflow.review.DefaultReview;
import org.sonar.core.review.workflow.review.MutableReview;
import java.util.List;
public interface ReviewStore {
- void store(MutableReview review);
+ void store(DefaultReview review);
void completeProjectSettings(Long projectId, Settings settings, List<String> propertyKeys);
}
/**
* @return non-null list of screens per review#violationId
*/
- public ListMultimap<Long, Screen> listAvailableScreens(Review[] reviews, DefaultWorkflowContext context, boolean verifyConditions) {
+ public ListMultimap<Long, Screen> listAvailableScreens(DefaultReview[] reviews, DefaultWorkflowContext context, boolean verifyConditions) {
ListMultimap<Long, Screen> result = ArrayListMultimap.create();
completeProjectSettings(context);
for (Map.Entry<String, Screen> entry : workflow.getScreensByCommand().entrySet()) {
String commandKey = entry.getKey();
if (!verifyConditions || verifyConditionsQuietly(null, context, workflow.getContextConditions(commandKey))) {
- for (Review review : reviews) {
+ for (DefaultReview review : reviews) {
if (!verifyConditions || verifyConditionsQuietly(review, context, workflow.getReviewConditions(commandKey))) {
result.put(review.getViolationId(), entry.getValue());
}
return workflow.getScreen(commandKey);
}
- public void execute(String commandKey, MutableReview review, DefaultWorkflowContext context, Map<String, String> parameters) {
+ public void execute(String commandKey, DefaultReview review, DefaultWorkflowContext context, Map<String, String> parameters) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(commandKey), "Missing command");
Preconditions.checkArgument(workflow.hasCommand(commandKey), "Unknown command: " + commandKey);
import org.sonar.core.review.workflow.review.Review;
import org.sonar.core.review.workflow.review.WorkflowContext;
+import javax.annotation.Nullable;
+
/**
* @since 3.1
*/
}
@Override
- public boolean doVerify(Review review, WorkflowContext context) {
- return !Strings.isNullOrEmpty(review.getProperties().get(propertyKey));
+ public boolean doVerify(@Nullable Review review, WorkflowContext context) {
+ return review != null && !Strings.isNullOrEmpty(review.getProperties().get(propertyKey));
}
}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.review.workflow.function;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import org.sonar.core.review.workflow.review.MutableReview;
-import org.sonar.core.review.workflow.review.Review;
-import org.sonar.core.review.workflow.review.WorkflowContext;
-
-import javax.annotation.Nullable;
-import java.util.Map;
-
-public final class TransitionFunction extends Function {
-
- private final String targetStatus;
- private final String targetResolution;
-
- public TransitionFunction(String targetStatus, @Nullable String targetResolution) {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(targetStatus), "Empty target status");
- this.targetStatus = targetStatus;
- this.targetResolution = targetResolution;
- }
-
- @Override
- public void doExecute(MutableReview review, Review initialReview, WorkflowContext context, Map<String, String> parameters) {
- review.setStatus(targetStatus);
- review.setResolution(targetResolution);
- }
-}
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
-public class Comment implements Cloneable {
+public final class Comment implements Cloneable {
private String markdownText;
private Long userId;
private Long violationId;
private Long reviewId;
- private Long ruleId;
- private Long assigneeId;
+ private String ruleRepositoryKey;
+ private String ruleKey;
private Long line;
private boolean switchedOff = false;
private boolean manual = false;
return this;
}
- public Long getRuleId() {
- return ruleId;
+ public String getRuleRepositoryKey() {
+ return ruleRepositoryKey;
}
- public DefaultReview setRuleId(Long ruleId) {
- this.ruleId = ruleId;
+ public DefaultReview setRuleRepositoryKey(String s) {
+ this.ruleRepositoryKey = s;
+ return this;
+ }
+
+ public String getRuleKey() {
+ return ruleKey;
+ }
+
+ public DefaultReview setRuleKey(String s) {
+ this.ruleKey = s;
return this;
}
return this;
}
- public Long getAssigneeId() {
- return assigneeId;
- }
-
- public DefaultReview setAssigneeId(Long l) {
- this.assigneeId = l;
- return this;
- }
-
public String getStatus() {
return status;
}
*/
public ImmutableReview cloneImmutable() {
ImmutableReview clone = new ImmutableReview();
- clone.setAssigneeId(assigneeId);
clone.setLine(line);
clone.setManual(manual);
clone.setMessage(message);
clone.setProperties(ImmutableMap.copyOf(getProperties()));
clone.setResolution(resolution);
clone.setReviewId(reviewId);
- clone.setRuleId(ruleId);
+ clone.setRuleKey(ruleKey);
+ clone.setRuleRepositoryKey(ruleRepositoryKey);
clone.setSeverity(severity);
clone.setStatus(status);
clone.setSwitchedOff(switchedOff);
private Long violationId;
private Long reviewId;
private Long ruleId;
- private Long assigneeId;
+ private String ruleRepositoryKey;
+ private String ruleKey;
private Long line;
private boolean switchedOff = false;
private boolean manual = false;
this.ruleId = ruleId;
}
- public Long getAssigneeId() {
- return assigneeId;
+ public String getRuleRepositoryKey() {
+ return ruleRepositoryKey;
}
- void setAssigneeId(Long assigneeId) {
- this.assigneeId = assigneeId;
+ void setRuleRepositoryKey(String ruleRepositoryKey) {
+ this.ruleRepositoryKey = ruleRepositoryKey;
+ }
+
+ public String getRuleKey() {
+ return ruleKey;
+ }
+
+ void setRuleKey(String ruleKey) {
+ this.ruleKey = ruleKey;
}
public Long getLine() {
public interface MutableReview extends Review {
- MutableReview setAssigneeId(Long assigneeId);
-
MutableReview setStatus(String s);
MutableReview setResolution(@Nullable String resolution);
public interface Review {
- Long getViolationId();
+ String getRuleRepositoryKey();
- Long getReviewId();
-
- Long getRuleId();
-
- Long getAssigneeId();
+ String getRuleKey();
boolean isSwitchedOff();
public void store() {
setupData("store");
ReviewDatabaseStore store = new ReviewDatabaseStore(getMyBatis());
- MutableReview review = new DefaultReview().setReviewId(1234L);
- review.setAssigneeId(33L);
+ DefaultReview review = new DefaultReview().setReviewId(1234L);
review.setStatus("CLOSED");
review.setResolution("RESOLVED");
review.setProperty("who", "me");
public void listAvailableScreensForReviews_empty() {
WorkflowEngine engine = new WorkflowEngine(new Workflow(), mock(ReviewStore.class), new Settings());
ListMultimap<Long, Screen> screens = engine.listAvailableScreens(
- new Review[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
+ new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
new DefaultWorkflowContext(), true);
assertThat(screens.size()).isEqualTo(0);
}
workflow.setScreen("resolve", screen);
WorkflowEngine engine = new WorkflowEngine(workflow, mock(ReviewStore.class), new Settings());
ListMultimap<Long, Screen> screens = engine.listAvailableScreens(
- new Review[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
+ new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
new DefaultWorkflowContext(), true);
assertThat(screens.size()).isEqualTo(2);
assertThat(screens.get(1000L)).containsExactly(screen);
WorkflowEngine engine = new WorkflowEngine(workflow, store, new Settings());
engine.listAvailableScreens(
- new Review[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
+ new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)},
new DefaultWorkflowContext().setProjectId(300L),
true);
settings.setProperty("foo", "bar");
WorkflowEngine engine = new WorkflowEngine(workflow, store, settings);
- MutableReview review = new DefaultReview().setViolationId(1000L);
+ DefaultReview review = new DefaultReview().setViolationId(1000L);
Map<String, String> parameters = Maps.newHashMap();
DefaultWorkflowContext context = new DefaultWorkflowContext().setProjectId(300L);
Settings settings = new Settings();// missing property 'foo'
WorkflowEngine engine = new WorkflowEngine(workflow, store, settings);
- MutableReview review = new DefaultReview().setViolationId(1000L);
+ DefaultReview review = new DefaultReview().setViolationId(1000L);
Map<String, String> parameters = Maps.newHashMap();
DefaultWorkflowContext context = new DefaultWorkflowContext().setProjectId(300L);
import org.sonar.core.review.workflow.condition.Condition;
import org.sonar.core.review.workflow.condition.HasProjectPropertyCondition;
import org.sonar.core.review.workflow.condition.StatusCondition;
-import org.sonar.core.review.workflow.function.TransitionFunction;
+import org.sonar.core.review.workflow.function.CommentFunction;
+import org.sonar.core.review.workflow.function.Function;
import org.sonar.core.review.workflow.screen.CommentScreen;
import static org.fest.assertions.Assertions.assertThat;
Workflow workflow = new Workflow();
workflow.addCommand("resolve");
- TransitionFunction function = new TransitionFunction("OPEN", "resolved");
+ Function function = new CommentFunction();
workflow.addFunction("resolve", function);
assertThat(workflow.getFunctions("resolve")).containsExactly(function);
thrown.expectMessage("Unknown command: resolve");
Workflow workflow = new Workflow();
- workflow.addFunction("resolve", new TransitionFunction("OPEN", "resolved"));
+ workflow.addFunction("resolve", new CommentFunction());
}
@Test
*/
package org.sonar.core.review.workflow.condition;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.sonar.core.review.workflow.review.DefaultReview;
import org.sonar.core.review.workflow.review.DefaultWorkflowContext;
import org.sonar.core.review.workflow.review.Review;
import static org.fest.assertions.Assertions.assertThat;
public class ResolutionConditionTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void failIfNoResolution() {
+ thrown.expect(IllegalArgumentException.class);
+ new ResolutionCondition();
+ }
+
@Test
public void getResolutions() {
ResolutionCondition condition = new ResolutionCondition("", "RESOLVED");
*/
package org.sonar.core.review.workflow.condition;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.sonar.core.review.workflow.review.DefaultReview;
import org.sonar.core.review.workflow.review.DefaultWorkflowContext;
import org.sonar.core.review.workflow.review.Review;
import static org.fest.assertions.Assertions.assertThat;
public class StatusConditionTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void failIfNoStatus() {
+ thrown.expect(IllegalArgumentException.class);
+ new StatusCondition();
+ }
+
+
@Test
public void getStatuses() {
StatusCondition condition = new StatusCondition("OPEN", "CLOSED");
resource_line="200"
severity="BLOCKER"
user_id="300"
+ assignee_id="33"
resource_id="400"
rule_id="500"
manual_violation="[true]"
updated_at="2012-05-18"
status="CLOSED"
resolution="RESOLVED"
- assignee_id="33"
data="who=me;why=because"
/>
resource_line="200"
severity="BLOCKER"
user_id="300"
+ assignee_id="33"
resource_id="400"
rule_id="500"
manual_violation="[true]"
updated_at="[null]"
status="OPEN"
resolution="[null]"
- assignee_id="[null]"
data="[null]"
/>
import org.sonar.core.purge.PurgeDao;
import org.sonar.core.resource.ResourceIndexerDao;
import org.sonar.core.review.workflow.WorkflowEngine;
+import org.sonar.core.review.workflow.review.DefaultReview;
import org.sonar.core.review.workflow.review.DefaultWorkflowContext;
import org.sonar.core.review.workflow.review.MutableReview;
import org.sonar.core.review.workflow.review.Review;
return getContainer().getComponentByType(WorkflowEngine.class).listAvailableScreens(review, context, true);
}
- public ListMultimap<Long, Screen> listAvailableReviewsScreens(Review[] reviews, DefaultWorkflowContext context) {
+ public ListMultimap<Long, Screen> listAvailableReviewsScreens(DefaultReview[] reviews, DefaultWorkflowContext context) {
return getContainer().getComponentByType(WorkflowEngine.class).listAvailableScreens(reviews, context, true);
}
return getContainer().getComponentByType(WorkflowEngine.class).getScreen(commandKey);
}
- public void executeReviewCommand(String commandKey, MutableReview review, DefaultWorkflowContext context, Map<String, String> parameters) {
+ public void executeReviewCommand(String commandKey, DefaultReview review, DefaultWorkflowContext context, Map<String, String> parameters) {
getContainer().getComponentByType(WorkflowEngine.class).execute(commandKey, review, context, parameters);
}
}
java_review=Java::OrgSonarCoreReviewWorkflowReview::DefaultReview.new
java_review.setViolationId(violation.id)
java_review.setSeverity(violation.severity.to_s)
- java_review.setRuleId(violation.rule_id)
+ java_review.setRuleKey(violation.rule.plugin_rule_key)
+ java_review.setRuleRepositoryKey(violation.rule.repository_key)
java_review.setSwitchedOff(violation.switched_off||false)
java_review.setMessage(violation.message)
java_review.setLine(violation.line)
java_review.setReviewId(review.id)
java_review.setStatus(review.status)
java_review.setResolution(review.resolution)
- java_review.setAssigneeId(review.assignee_id)
java_review.setManual(review.manual_violation)
java_review.setPropertiesAsString(review.data)
else