import org.sonar.api.ServerComponent;
import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.condition.IsUnResolved;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.server.user.UserSession;
public CommentAction() {
super(COMMENT_ACTION_KEY);
- super.setConditions(new IsUnResolved());
}
@Override
String projectParam = parameters.get("project");
checkMandatorySizeParameter(name, "name", 200, result);
- checkOptionnalSizeParameter(description, "description", 1000, result);
+ checkOptionalSizeParameter(description, "description", 1000, result);
// Can only set project on creation
if (existingActionPlan == null) {
checkMandatoryParameter(id, "id", result);
}
checkMandatorySizeParameter(name, "name", 100, result);
- checkOptionnalSizeParameter(description, "description", 4000, result);
+ checkOptionalSizeParameter(description, "description", 4000, result);
if (result.ok()) {
DefaultIssueFilter defaultIssueFilter = DefaultIssueFilter.create(name)
return result;
}
+ /**
+ * Execute a bulk change
+ */
+ public Result<IssueBulkChangeResult> bulkChange(Map<String, Object> props, String comment) {
+ Result<IssueBulkChangeResult> result = Result.of();
+ try {
+ IssueBulkChangeQuery issueBulkChangeQuery = new IssueBulkChangeQuery(props, comment);
+ result.set(issueBulkChangeService.execute(issueBulkChangeQuery, UserSession.get()));
+ } catch (Exception e) {
+ result.addError(e.getMessage());
+ }
+ return result;
+ }
+
private void checkMandatoryParameter(String value, String paramName, Result result) {
if (Strings.isNullOrEmpty(value)) {
result.addError(Result.Message.ofL10n("errors.cant_be_empty", paramName));
}
}
- private void checkOptionnalSizeParameter(String value, String paramName, Integer size, Result result) {
+ private void checkOptionalSizeParameter(String value, String paramName, Integer size, Result result) {
if (!Strings.isNullOrEmpty(value) && value.length() > size) {
result.addError(Result.Message.ofL10n("errors.is_too_long", paramName, size));
}
}
- /**
- * Execute a bulk change
- */
- public Result<IssueBulkChangeResult> executeBulkChange(Map<String, Object> props) {
- Result<IssueBulkChangeResult> result = Result.of();
- try {
- IssueBulkChangeQuery issueBulkChangeQuery = new IssueBulkChangeQuery(props);
- result.set(issueBulkChangeService.execute(issueBulkChangeQuery, UserSession.get()));
- } catch (Exception e) {
- result.addError(e.getMessage());
- }
- return result;
- }
-
}
\ No newline at end of file
package org.sonar.server.issue;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Strings;
import org.apache.commons.lang.StringUtils;
import org.sonar.server.util.RubyUtils;
Map<String, Map<String, Object>> propertiesByActions = new HashMap<String, Map<String, Object>>();
- public IssueBulkChangeQuery(Map<String, Object> props) {
- parse(props, null);
- }
-
public IssueBulkChangeQuery(Map<String, Object> props, String comment) {
parse(props, comment);
}
+ @VisibleForTesting
+ IssueBulkChangeQuery(Map<String, Object> props) {
+ parse(props, null);
+ }
+
private void parse(Map<String, Object> props, String comment) {
this.comment = comment;
this.issues = RubyUtils.toStrings(props.get("issues"));
throw new IllegalArgumentException("At least one action must be provided");
}
for (String action : actions) {
- propertiesByActions.put(action, getActionProps(action, props));
+ Map<String, Object> actionProperties = getActionProps(action, props);
+ if (actionProperties.isEmpty()) {
+ throw new IllegalArgumentException("Missing properties for action: "+ action);
+ }
+ propertiesByActions.put(action, actionProperties);
+ }
+ if (!Strings.isNullOrEmpty(comment)) {
+ actions.add(CommentAction.COMMENT_ACTION_KEY);
+ Map<String, Object> commentMap = newHashMap();
+ commentMap.put(CommentAction.COMMENT_ACTION_KEY, comment);
+ propertiesByActions.put(CommentAction.COMMENT_ACTION_KEY, commentMap);
}
}
return propertiesByActions.get(action);
}
- public String getComment() {
- return comment;
- }
-
private static Map<String, Object> getActionProps(String action, Map<String, Object> props) {
Map<String, Object> actionProps = newHashMap();
for (Map.Entry<String, Object> propsEntry : props.entrySet()) {
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.issue;
-
-import org.sonar.api.ServerComponent;
-import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.condition.IsUnResolved;
-import org.sonar.api.issue.internal.DefaultIssue;
-import org.sonar.server.user.UserSession;
-
-import java.util.List;
-import java.util.Map;
-
-
-public class TransitionAction extends Action implements ServerComponent {
-
- public static final String TRANSITION_ACTION_KEY = "transition";
-
- public TransitionAction() {
- super(TRANSITION_ACTION_KEY);
- super.setConditions(new IsUnResolved());
- }
-
- @Override
- public boolean verify(Map<String, Object> properties, List<Issue> issues, UserSession userSession) {
- return true;
- }
-
- @Override
- public boolean execute(Map<String, Object> properties, Context context) {
- context.issueUpdater().addComment((DefaultIssue) context.issue(), transition(properties), context.issueChangeContext());
- return true;
- }
-
- private String transition(Map<String, Object> properties) {
- return (String) properties.get("transition");
- }
-}
\ No newline at end of file
@Test
public void should_support_only_unresolved_issues(){
- assertThat(action.supports(new DefaultIssue().setStatus(Issue.STATUS_OPEN))).isTrue();
- assertThat(action.supports(new DefaultIssue().setStatus(Issue.STATUS_CLOSED))).isTrue();
+ assertThat(action.supports(new DefaultIssue().setResolution(null))).isTrue();
+ assertThat(action.supports(new DefaultIssue().setResolution(Issue.RESOLUTION_FIXED))).isFalse();
}
}
\ No newline at end of file
}
@Test
- public void should_support_only_unresolved_issues(){
- assertThat(action.supports(new DefaultIssue().setStatus(Issue.STATUS_OPEN))).isTrue();
- assertThat(action.supports(new DefaultIssue().setStatus(Issue.STATUS_CLOSED))).isTrue();
+ public void should_support_all_issues(){
+ assertThat(action.supports(new DefaultIssue().setResolution(null))).isTrue();
+ assertThat(action.supports(new DefaultIssue().setResolution(Issue.RESOLUTION_FIXED))).isTrue();
}
}
params.put("assign.assignee", "arthur");
params.put("set_severity.severity", "MINOR");
params.put("plan.plan", "3.7");
- service.executeBulkChange(params);
+ Result<IssueBulkChangeResult> result = service.bulkChange(params, "My comment");
+ assertThat(result.errors()).isEmpty();
+ assertThat(result.ok()).isTrue();
verify(issueBulkChangeService).execute(any(IssueBulkChangeQuery.class), any(UserSession.class));
}
params.put("issues", newArrayList("ABCD", "EFGH"));
params.put("actions", newArrayList("assign"));
params.put("assign.assignee", "arthur");
- Result result = service.executeBulkChange(params);
+ Result result = service.bulkChange(params, "A comment");
assertThat(result.ok()).isFalse();
assertThat(((Result.Message) result.errors().get(0)).text()).contains("Error");
}
assertThat(issueBulkChangeQuery.issues()).containsOnly("ABCD", "EFGH");
}
+ @Test
+ public void should_create_query_with_comment(){
+ Map<String, Object> params = newHashMap();
+ params.put("issues", newArrayList("ABCD", "EFGH"));
+ params.put("actions", newArrayList("assign"));
+ params.put("assign.assignee", "arthur");
+
+ IssueBulkChangeQuery issueBulkChangeQuery = new IssueBulkChangeQuery(params, "My comment for bulk change");
+ assertThat(issueBulkChangeQuery.actions()).containsOnly("assign", "comment");
+ assertThat(issueBulkChangeQuery.properties("comment").get("comment")).isEqualTo("My comment for bulk change");
+ }
+
@Test
public void should_get_properties_action(){
Map<String, Object> params = newHashMap();
@Test(expected = IllegalArgumentException.class)
public void fail_to_build_if_no_issue(){
Map<String, Object> params = newHashMap();
- params.put("actions", newArrayList("do_transition", "assign", "set_severity", "plan"));
+ params.put("actions", newArrayList("assign"));
+ params.put("assign.assignee", "arthur");
new IssueBulkChangeQuery(params);
}
public void fail_to_build_if_issues_are_empty(){
Map<String, Object> params = newHashMap();
params.put("issues", Collections.emptyList());
- params.put("actions", newArrayList("do_transition", "assign", "set_severity", "plan"));
+ params.put("actions", newArrayList("assign"));
+ params.put("assign.assignee", "arthur");
new IssueBulkChangeQuery(params);
}
new IssueBulkChangeQuery(params);
}
+ @Test(expected = IllegalArgumentException.class)
+ public void fail_to_build_if_action_properties_are_empty(){
+ Map<String, Object> params = newHashMap();
+ params.put("issues", Collections.emptyList());
+ params.put("actions", newArrayList("assign"));
+ new IssueBulkChangeQuery(params);
+ }
+
}
Map<String, Object> properties = newHashMap();
properties.put("issues", "ABCD");
properties.put("actions", "assign");
+ properties.put("assign.assignee", "fred");
when(action.supports(any(Issue.class))).thenReturn(true);
when(action.execute(anyMap(), any(IssueBulkChangeService.ActionContext.class))).thenReturn(true);
Map<String, Object> properties = newHashMap();
properties.put("issues", "ABCD");
properties.put("actions", "assign");
+ properties.put("assign.assignee", "fred");
when(action.supports(any(Issue.class))).thenReturn(false);
Map<String, Object> properties = newHashMap();
properties.put("issues", "ABCD");
properties.put("actions", "assign");
+ properties.put("assign.assignee", "fred");
when(action.supports(any(Issue.class))).thenReturn(true);
when(action.execute(anyMap(), any(IssueBulkChangeService.ActionContext.class))).thenReturn(false);
Map<String, Object> properties = newHashMap();
properties.put("issues", "ABCD");
properties.put("actions", "assign");
+ properties.put("assign.assignee", "fred");
when(action.supports(any(Issue.class))).thenReturn(true);
doThrow(new RuntimeException("Error")).when(action).execute(anyMap(), any(IssueBulkChangeService.ActionContext.class));
Map<String, Object> properties = newHashMap();
properties.put("issues", "ABCD");
properties.put("actions", "assign");
+ properties.put("assign.assignee", "fred");
IssueBulkChangeQuery issueBulkChangeQuery = new IssueBulkChangeQuery(properties);
try {
service.execute(issueBulkChangeQuery, userSession);
Map<String, Object> properties = newHashMap();
properties.put("issues", "ABCD");
properties.put("actions", "unknown");
+ properties.put("unknown.unknown", "unknown");
IssueBulkChangeQuery issueBulkChangeQuery = new IssueBulkChangeQuery(properties);
try {
service.execute(issueBulkChangeQuery, userSession);
@Test
public void should_support_only_unresolved_issues(){
- assertThat(action.supports(new DefaultIssue().setStatus(Issue.STATUS_OPEN))).isTrue();
- assertThat(action.supports(new DefaultIssue().setStatus(Issue.STATUS_CLOSED))).isTrue();
+ assertThat(action.supports(new DefaultIssue().setResolution(null))).isTrue();
+ assertThat(action.supports(new DefaultIssue().setResolution(Issue.RESOLUTION_FIXED))).isFalse();
}
}
\ No newline at end of file
@Test
public void should_support_only_unresolved_issues(){
- assertThat(action.supports(new DefaultIssue().setStatus(Issue.STATUS_OPEN))).isTrue();
- assertThat(action.supports(new DefaultIssue().setStatus(Issue.STATUS_CLOSED))).isTrue();
+ assertThat(action.supports(new DefaultIssue().setResolution(null))).isTrue();
+ assertThat(action.supports(new DefaultIssue().setResolution(Issue.RESOLUTION_FIXED))).isFalse();
}
}