private final ResourceDao resourceDao;
private final ActionService actionService;
private final IssueFilterService issueFilterService;
+ private final IssueBulkChangeService issueBulkChangeService;
public InternalRubyIssueService(IssueService issueService,
IssueCommentService commentService,
IssueChangelogService changelogService, ActionPlanService actionPlanService,
IssueStatsFinder issueStatsFinder, ResourceDao resourceDao, ActionService actionService,
- IssueFilterService issueFilterService) {
+ IssueFilterService issueFilterService, IssueBulkChangeService issueBulkChangeService) {
this.issueService = issueService;
this.commentService = commentService;
this.changelogService = changelogService;
this.resourceDao = resourceDao;
this.actionService = actionService;
this.issueFilterService = issueFilterService;
+ this.issueBulkChangeService = issueBulkChangeService;
}
public IssueStatsFinder.IssueStatsResult findIssueAssignees(Map<String, Object> params) {
}
}
- public String serializeFilterQuery(Map<String, Object> filterQuery){
+ public String serializeFilterQuery(Map<String, Object> filterQuery) {
return issueFilterService.serializeFilterQuery(filterQuery);
}
return issueFilterService.execute(issueQuery);
}
- private void overrideProps(Map<String, Object> props, Map<String, Object> overrideProps){
+ private void overrideProps(Map<String, Object> props, Map<String, Object> overrideProps) {
overrideProp(props, overrideProps, "pageSize");
overrideProp(props, overrideProps, "pageIndex");
}
- private void overrideProp(Map<String, Object> props, Map<String, Object> overrideProps, String key){
+ private void overrideProp(Map<String, Object> props, Map<String, Object> overrideProps, String key) {
if (overrideProps.containsKey(key)) {
props.put(key, overrideProps.get(key));
}
}
}
+ /**
+ * Execute a bulk change
+ */
+ public Result<List<Issue>> executebulkChange(Map<String, Object> props) {
+ Result<List<Issue>> result = Result.of();
+ try {
+ IssueBulkChangeQuery issueBulkChangeQuery = toIssueBulkChangeQuery(props);
+ result.set(issueBulkChangeService.execute(issueBulkChangeQuery, UserSession.get()));
+ } catch (Exception e) {
+ result.addError(e.getMessage());
+ }
+ return result;
+ }
+
+ private IssueBulkChangeQuery toIssueBulkChangeQuery(Map<String, Object> props) {
+ return IssueBulkChangeQuery.builder()
+ .issueKeys(RubyUtils.toStrings(props.get("issues")))
+ .assignee((String) props.get("assignee"))
+ .plan((String) props.get("plan"))
+ .severity((String) props.get("severity"))
+ .transition((String) props.get("transition"))
+ .comment((String) props.get("comment"))
+ .build();
+ }
+
}
\ No newline at end of file
this.userFinder = userFinder;
}
- public Result<List<Issue>> execute(IssueBulkChangeQuery issueBulkChangeQuery, UserSession userSession) {
- Result<List<Issue>> result = Result.of();
+ public List<Issue> execute(IssueBulkChangeQuery issueBulkChangeQuery, UserSession userSession) {
List<Issue> issues = newArrayList();
verifyLoggedIn(userSession);
issueNotifications.sendChanges(defaultIssue, context, issueQueryResult);
issues.add(defaultIssue);
} catch (Exception e) {
- result.addError(e.getMessage());
+ // Do nothing, just go to the next issue
}
}
- result.set(issues);
- return result;
+ return issues;
}
private void verifyLoggedIn(UserSession userSession) {
IssueStatsFinder issueStatsFinder = mock(IssueStatsFinder.class);
ActionService actionService = mock(ActionService.class);
IssueFilterService issueFilterService = mock(IssueFilterService.class);
+ IssueBulkChangeService issueBulkChangeService = mock(IssueBulkChangeService.class);
@Before
public void setUp() {
ResourceDto project = new ResourceDto().setKey("org.sonar.Sample");
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(project);
- service = new InternalRubyIssueService(issueService, commentService, changelogService, actionPlanService, issueStatsFinder, resourceDao, actionService, issueFilterService);
+ service = new InternalRubyIssueService(issueService, commentService, changelogService, actionPlanService, issueStatsFinder, resourceDao, actionService,
+ issueFilterService, issueBulkChangeService);
}
@Test
verify(issueFilterService).verifyCurrentUserCanReadFilter(eq(issueFilter), any(UserSession.class));
}
+ @Test
+ public void should_execute_bulk_change() {
+ service.executebulkChange(Maps.<String, Object>newHashMap());
+ verify(issueBulkChangeService).execute(any(IssueBulkChangeQuery.class), any(UserSession.class));
+ }
+
+ @Test
+ public void should_no_execute_bulk_change_if_unexpected_error() {
+ doThrow(new RuntimeException("Error")).when(issueBulkChangeService).execute(any(IssueBulkChangeQuery.class), any(UserSession.class));
+
+ Result result = service.executebulkChange(Maps.<String, Object>newHashMap());
+ assertThat(result.ok()).isFalse();
+ assertThat(((Result.Message) result.errors().get(0)).text()).contains("Error");
+ }
+
private String createLongString(int size) {
String result = "";
for (int i = 0; i < size; i++) {
when(userFinder.findByLogin(assignee)).thenReturn(new DefaultUser());
IssueBulkChangeQuery issueBulkChangeQuery = IssueBulkChangeQuery.builder().issueKeys(newArrayList(issue.key())).assignee(assignee).build();
- Result result = service.execute(issueBulkChangeQuery, userSession);
- assertThat(result.ok()).isTrue();
- assertThat((List)result.get()).hasSize(1);
+ List<Issue> result = service.execute(issueBulkChangeQuery, userSession);
+ assertThat(result).hasSize(1);
verify(issueUpdater).assign(eq(issue), eq(assignee), any(IssueChangeContext.class));
verifyNoMoreInteractions(issueUpdater);
when(actionPlanService.findByKey(actionPlanKey, userSession)).thenReturn(new DefaultActionPlan());
IssueBulkChangeQuery issueBulkChangeQuery = IssueBulkChangeQuery.builder().issueKeys(newArrayList(issue.key())).plan(actionPlanKey).build();
- Result result = service.execute(issueBulkChangeQuery, userSession);
- assertThat(result.ok()).isTrue();
- assertThat((List)result.get()).hasSize(1);
+ List<Issue> result = service.execute(issueBulkChangeQuery, userSession);
+ assertThat(result).hasSize(1);
verify(issueUpdater).plan(eq(issue), eq(actionPlanKey), any(IssueChangeContext.class));
verifyNoMoreInteractions(issueUpdater);
String severity = "MINOR";
IssueBulkChangeQuery issueBulkChangeQuery = IssueBulkChangeQuery.builder().issueKeys(newArrayList(issue.key())).severity(severity).build();
- Result result = service.execute(issueBulkChangeQuery, userSession);
- assertThat(result.ok()).isTrue();
- assertThat((List)result.get()).hasSize(1);
+ List<Issue> result = service.execute(issueBulkChangeQuery, userSession);
+ assertThat(result).hasSize(1);
verify(issueUpdater).setManualSeverity(eq(issue), eq(severity), any(IssueChangeContext.class));
verifyNoMoreInteractions(issueUpdater);
when(workflow.doTransition(eq(issue), eq(transition), any(IssueChangeContext.class))).thenReturn(true);
IssueBulkChangeQuery issueBulkChangeQuery = IssueBulkChangeQuery.builder().issueKeys(newArrayList(issue.key())).transition(transition).build();
- Result result = service.execute(issueBulkChangeQuery, userSession);
- assertThat(result.ok()).isTrue();
- assertThat((List)result.get()).hasSize(1);
+ List<Issue> result = service.execute(issueBulkChangeQuery, userSession);
+ assertThat(result).hasSize(1);
verify(workflow).doTransition(eq(issue), eq(transition), any(IssueChangeContext.class));
verifyNoMoreInteractions(issueUpdater);
String comment = "Bulk change comment";
IssueBulkChangeQuery issueBulkChangeQuery = IssueBulkChangeQuery.builder().issueKeys(newArrayList(issue.key())).comment(comment).build();
- Result result = service.execute(issueBulkChangeQuery, userSession);
- assertThat(result.ok()).isTrue();
- assertThat((List)result.get()).hasSize(1);
+ List<Issue> result = service.execute(issueBulkChangeQuery, userSession);
+ assertThat(result).hasSize(1);
verify(issueUpdater).addComment(eq(issue), eq(comment), any(IssueChangeContext.class));
verifyNoMoreInteractions(issueUpdater);
// The first call the change severity is ok, the second will fail
when(issueUpdater.setManualSeverity(any(DefaultIssue.class), eq("MAJOR"),any(IssueChangeContext.class))).thenReturn(true).thenThrow(new RuntimeException("Cant change severity"));
- Result result = service.execute(issueBulkChangeQuery, userSession);
- assertThat(result.ok()).isFalse();
- assertThat(((Result.Message) result.errors().get(0)).text()).isEqualTo("Cant change severity");
-
- List<Issue> issues = (List) result.get();
- assertThat(issues).hasSize(1);
- assertThat(issues.get(0).key()).isEqualTo("ABCD");
+ List<Issue> result = service.execute(issueBulkChangeQuery, userSession);
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0).key()).isEqualTo("ABCD");
verify(issueStorage).save(eq(issue));
verifyNoMoreInteractions(issueStorage);