import org.sonar.server.ws.WsUtils;
import org.sonarqube.ws.Issues;
-import static java.util.Collections.singleton;
+import static java.util.Collections.singletonList;
import static org.sonar.server.issue.ws.SearchAdditionalField.ALL_ADDITIONAL_FIELDS;
public class OperationResponseWriter {
this.format = format;
}
- public void write(String issueKey, Request request, Response response) {
- SearchResponseLoader.Collector collector = new SearchResponseLoader.Collector(ALL_ADDITIONAL_FIELDS, singleton(issueKey));
- SearchResponseData data = loader.load(collector, null);
-
- Issues.Operation responseBody = format.formatOperation(data);
-
- WsUtils.writeProtobuf(responseBody, request, response);
- }
-
public void write(String issueKey, SearchResponseData preloadedResponseData, Request request, Response response) {
- SearchResponseLoader.Collector collector = new SearchResponseLoader.Collector(ALL_ADDITIONAL_FIELDS, singleton(issueKey));
+ SearchResponseLoader.Collector collector = new SearchResponseLoader.Collector(ALL_ADDITIONAL_FIELDS, singletonList(issueKey));
SearchResponseData data = loader.load(preloadedResponseData, collector, null);
Issues.Operation responseBody = format.formatOperation(data);
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.issue.IssueDto;
import org.sonar.server.issue.IssueFieldsSetter;
import org.sonar.server.issue.IssueFinder;
import org.sonar.server.issue.IssueUpdater;
public void handle(Request request, Response response) throws Exception {
String key = request.mandatoryParam(PARAM_ISSUE);
List<String> tags = MoreObjects.firstNonNull(request.paramAsStrings(PARAM_TAGS), Collections.<String>emptyList());
- setTags(key, tags);
- responseWriter.write(key, request, response);
+ SearchResponseData preloadedSearchResponseData = setTags(key, tags);
+ responseWriter.write(key, preloadedSearchResponseData, request, response);
}
- private void setTags(String issueKey, List<String> tags) {
+ private SearchResponseData setTags(String issueKey, List<String> tags) {
userSession.checkLoggedIn();
try (DbSession session = dbClient.openSession(false)) {
- DefaultIssue issue = issueFinder.getByKey(session, issueKey).toDefaultIssue();
+ IssueDto issueDto = issueFinder.getByKey(session, issueKey);
+ DefaultIssue issue = issueDto.toDefaultIssue();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
if (issueFieldsSetter.setTags(issue, tags, context)) {
- issueUpdater.saveIssue(session, issue, context, null);
+ return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null);
}
+ return new SearchResponseData(issueDto);
}
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
import org.sonar.api.config.MapSettings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private OperationResponseWriter responseWriter = mock(OperationResponseWriter.class);
private IssueIndexer issueIndexer = new IssueIndexer(esTester.client(), new IssueIteratorFactory(dbClient));
+ private ArgumentCaptor<SearchResponseData> preloadedSearchResponseDataCaptor = ArgumentCaptor.forClass(SearchResponseData.class);
private WsActionTester ws = new WsActionTester(new SetTagsAction(userSession, dbClient, new IssueFinder(dbClient, userSession), new IssueFieldsSetter(),
new IssueUpdater(dbClient,
call(issueDto.getKey(), "bug", "todo");
- verify(responseWriter).write(eq(issueDto.getKey()), any(Request.class), any(Response.class));
+ verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class));
+ verifyContentOfPreloadedSearchResponseData(issueDto);
IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issueDto.getKey()).get();
assertThat(issueReloaded.getTags()).containsOnly("bug", "todo");
}
userSession.logIn("john").addProjectPermission(permission, dbClient.componentDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get());
}
+ private void verifyContentOfPreloadedSearchResponseData(IssueDto issue) {
+ SearchResponseData preloadedSearchResponseData = preloadedSearchResponseDataCaptor.getValue();
+ assertThat(preloadedSearchResponseData.getIssues())
+ .extracting(IssueDto::getKey)
+ .containsOnly(issue.getKey());
+ assertThat(preloadedSearchResponseData.getRules())
+ .extracting(RuleDefinitionDto::getKey)
+ .containsOnly(issue.getRuleKey());
+ assertThat(preloadedSearchResponseData.getComponents())
+ .extracting(ComponentDto::uuid)
+ .containsOnly(issue.getComponentUuid(), issue.getProjectUuid());
+ }
+
}