IssueChangelog.class,
SearchResponseLoader.class,
TextRangeResponseFormatter.class,
+ UserResponseFormatter.class,
SearchResponseFormat.class,
OperationResponseWriter.class,
AddCommentAction.class,
import org.sonar.db.user.UserDto;
import org.sonar.markdown.Markdown;
import org.sonar.server.es.Facets;
-import org.sonar.server.issue.AvatarResolver;
import org.sonar.server.issue.TextRangeResponseFormatter;
import org.sonar.server.issue.workflow.Transition;
import org.sonarqube.ws.Common;
+import org.sonarqube.ws.Common.User;
import org.sonarqube.ws.Issues;
import org.sonarqube.ws.Issues.Actions;
import org.sonarqube.ws.Issues.Comment;
private final Durations durations;
private final Languages languages;
- private final AvatarResolver avatarFactory;
private final TextRangeResponseFormatter textRangeFormatter;
+ private final UserResponseFormatter userFormatter;
- public SearchResponseFormat(Durations durations, Languages languages, AvatarResolver avatarFactory,
- TextRangeResponseFormatter textRangeFormatter) {
+ public SearchResponseFormat(Durations durations, Languages languages, TextRangeResponseFormatter textRangeFormatter, UserResponseFormatter userFormatter) {
this.durations = durations;
this.languages = languages;
- this.avatarFactory = avatarFactory;
this.textRangeFormatter = textRangeFormatter;
+ this.userFormatter = userFormatter;
}
SearchWsResponse formatSearch(Set<SearchAdditionalField> fields, SearchResponseData data, Paging paging, Facets facets) {
Users.Builder wsUsers = Users.newBuilder();
List<UserDto> users = data.getUsers();
if (users != null) {
+ User.Builder builder = User.newBuilder();
for (UserDto user : users) {
- wsUsers.addUsers(formatUser(user));
+ wsUsers.addUsers(userFormatter.formatUser(builder, user));
}
}
return wsUsers;
}
- private Users.User.Builder formatUser(UserDto user) {
- Users.User.Builder builder = Users.User.newBuilder()
- .setLogin(user.getLogin())
- .setName(nullToEmpty(user.getName()))
- .setActive(user.isActive());
- ofNullable(emptyToNull(user.getEmail())).ifPresent(email -> builder.setAvatar(avatarFactory.create(user)));
- return builder;
- }
-
private Issues.Languages.Builder formatLanguages() {
Issues.Languages.Builder wsLangs = Issues.Languages.newBuilder();
Issues.Language.Builder wsLang = Issues.Language.newBuilder();
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.ws;
+
+import org.sonar.db.user.UserDto;
+import org.sonar.server.issue.AvatarResolver;
+import org.sonarqube.ws.Common;
+
+import static com.google.common.base.Strings.emptyToNull;
+import static com.google.common.base.Strings.nullToEmpty;
+import static java.util.Optional.ofNullable;
+
+public class UserResponseFormatter {
+ private final AvatarResolver avatarResolver;
+
+ public UserResponseFormatter(AvatarResolver avatarResolver) {
+ this.avatarResolver = avatarResolver;
+ }
+
+ public Common.User formatUser(Common.User.Builder builder, UserDto user) {
+ builder
+ .clear()
+ .setLogin(user.getLogin())
+ .setName(nullToEmpty(user.getName()))
+ .setActive(user.isActive());
+ ofNullable(emptyToNull(user.getEmail())).ifPresent(email -> builder.setAvatar(avatarResolver.create(user)));
+ return builder.build();
+ }
+}
import org.sonar.db.protobuf.DbIssues;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.issue.TextRangeResponseFormatter;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.issue.IssueChangelog;
import org.sonar.server.issue.IssueChangelog.ChangelogLoadingContext;
+import org.sonar.server.issue.TextRangeResponseFormatter;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.security.SecurityStandards;
import org.sonar.server.security.SecurityStandards.SQCategory;
private DbClient dbClient = dbTester.getDbClient();
private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
- private TextRangeResponseFormatter commonFormatter = new TextRangeResponseFormatter();
+ private TextRangeResponseFormatter textRangeFormatter = new TextRangeResponseFormatter();
private HotspotWsResponseFormatter responseFormatter = new HotspotWsResponseFormatter(defaultOrganizationProvider);
private IssueChangelog issueChangelog = Mockito.mock(IssueChangelog.class);
- private ShowAction underTest = new ShowAction(dbClient, userSessionRule, responseFormatter, commonFormatter, issueChangelog);
+ private ShowAction underTest = new ShowAction(dbClient, userSessionRule, responseFormatter, textRangeFormatter, issueChangelog);
private WsActionTester actionTester = new WsActionTester(underTest);
@Test
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new IssueWsModule().configure(container);
- assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 30);
+ assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 31);
}
}
import org.sonar.db.issue.IssueDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
+import org.sonar.server.issue.AvatarResolverImpl;
import org.sonar.server.issue.TextRangeResponseFormatter;
import org.sonar.server.es.EsTester;
-import org.sonar.server.issue.AvatarResolverImpl;
import org.sonar.server.issue.IssueFieldsSetter;
import org.sonar.server.issue.TransitionService;
import org.sonar.server.issue.index.IssueIndex;
private IssueWorkflow issueWorkflow = new IssueWorkflow(new FunctionExecutor(issueFieldsSetter), issueFieldsSetter);
private SearchResponseLoader searchResponseLoader = new SearchResponseLoader(userSession, dbClient, new TransitionService(userSession, issueWorkflow));
private Languages languages = new Languages();
- private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), languages, new AvatarResolverImpl(), new TextRangeResponseFormatter());
+ private UserResponseFormatter userFormatter = new UserResponseFormatter(new AvatarResolverImpl());
+ private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), languages, new TextRangeResponseFormatter(), userFormatter);
private PermissionIndexerTester permissionIndexer = new PermissionIndexerTester(es, issueIndexer);
private WsActionTester ws = new WsActionTester(new SearchAction(userSession, issueIndex, issueQueryFactory, searchResponseLoader, searchResponseFormat,
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.user.UserDto;
-import org.sonar.server.issue.TextRangeResponseFormatter;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.StartupIndexer;
import org.sonar.server.issue.AvatarResolverImpl;
+import org.sonar.server.issue.TextRangeResponseFormatter;
import org.sonar.server.issue.TransitionService;
import org.sonar.server.issue.index.IssueIndex;
import org.sonar.server.issue.index.IssueIndexer;
private IssueQueryFactory issueQueryFactory = new IssueQueryFactory(db.getDbClient(), Clock.systemUTC(), userSession);
private SearchResponseLoader searchResponseLoader = new SearchResponseLoader(userSession, db.getDbClient(), new TransitionService(userSession, null));
private Languages languages = new Languages();
- private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), languages, new AvatarResolverImpl(), new TextRangeResponseFormatter());
+ private UserResponseFormatter userFormatter = new UserResponseFormatter(new AvatarResolverImpl());
+ private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), languages, new TextRangeResponseFormatter(), userFormatter);
private WsActionTester ws = new WsActionTester(
new SearchAction(userSession, issueIndex, issueQueryFactory, searchResponseLoader, searchResponseFormat,
private IssueWorkflow issueWorkflow = new IssueWorkflow(new FunctionExecutor(issueFieldsSetter), issueFieldsSetter);
private SearchResponseLoader searchResponseLoader = new SearchResponseLoader(userSession, dbClient, new TransitionService(userSession, issueWorkflow));
private Languages languages = new Languages();
- private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), languages, new AvatarResolverImpl(), new TextRangeResponseFormatter());
+ private UserResponseFormatter userFormatter = new UserResponseFormatter(new AvatarResolverImpl());
+ private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), languages, new TextRangeResponseFormatter(), userFormatter);
private WsActionTester ws = new WsActionTester(new SearchAction(userSession, issueIndex, issueQueryFactory, searchResponseLoader, searchResponseFormat,
new MapSettings().asConfig(), System2.INSTANCE, dbClient));
private StartupIndexer permissionIndexer = new PermissionIndexer(dbClient, es.client(), issueIndexer);
private IssueWorkflow issueWorkflow = new IssueWorkflow(new FunctionExecutor(issueFieldsSetter), issueFieldsSetter);
private SearchResponseLoader searchResponseLoader = new SearchResponseLoader(userSession, dbClient, new TransitionService(userSession, issueWorkflow));
private Languages languages = new Languages();
- private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), languages, new AvatarResolverImpl(), new TextRangeResponseFormatter());
+ private UserResponseFormatter userFormatter = new UserResponseFormatter(new AvatarResolverImpl());
+ private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), languages, new TextRangeResponseFormatter(), userFormatter);
private PermissionIndexerTester permissionIndexer = new PermissionIndexerTester(es, issueIndexer);
private SearchAction underTest = new SearchAction(userSession, issueIndex, issueQueryFactory, searchResponseLoader, searchResponseFormat,
optional string msg = 3;
}
+message User {
+ optional string login = 1;
+ optional string name = 2;
+ optional string avatar = 3;
+ optional bool active = 4;
+}
+
message Changelog {
optional string user = 1;
optional string userName = 2;
optional Issue issue = 1;
repeated Component components = 2;
repeated sonarqube.ws.commons.Rule rules = 3;
- repeated Users.User users = 4;
+ repeated sonarqube.ws.commons.User users = 4;
}
message AddCommentResponse {
optional Issue issue = 1;
repeated Component components = 2;
repeated sonarqube.ws.commons.Rule rules = 3;
- repeated Users.User users = 4;
+ repeated sonarqube.ws.commons.User users = 4;
}
message AssignResponse {
optional Issue issue = 1;
repeated Component components = 2;
repeated sonarqube.ws.commons.Rule rules = 3;
- repeated Users.User users = 4;
+ repeated sonarqube.ws.commons.User users = 4;
}
message DeleteCommentResponse {
optional Issue issue = 1;
repeated Component components = 2;
repeated sonarqube.ws.commons.Rule rules = 3;
- repeated Users.User users = 4;
+ repeated sonarqube.ws.commons.User users = 4;
}
message DoTransitionResponse {
optional Issue issue = 1;
repeated Component components = 2;
repeated sonarqube.ws.commons.Rule rules = 3;
- repeated Users.User users = 4;
+ repeated sonarqube.ws.commons.User users = 4;
}
message SetSeverityResponse {
optional Issue issue = 1;
repeated Component components = 2;
repeated sonarqube.ws.commons.Rule rules = 3;
- repeated Users.User users = 4;
+ repeated sonarqube.ws.commons.User users = 4;
}
message SetTagsResponse {
optional Issue issue = 1;
repeated Component components = 2;
repeated sonarqube.ws.commons.Rule rules = 3;
- repeated Users.User users = 4;
+ repeated sonarqube.ws.commons.User users = 4;
}
message SetTypeResponse {
optional Issue issue = 1;
repeated Component components = 2;
repeated sonarqube.ws.commons.Rule rules = 3;
- repeated Users.User users = 4;
+ repeated sonarqube.ws.commons.User users = 4;
}
message TagsResponse {
repeated string tags = 1;
}
message Users {
- repeated User users = 1;
-
- message User {
- optional string login = 1;
- optional string name = 2;
- optional string avatar = 3;
- optional bool active = 4;
- }
+ repeated sonarqube.ws.commons.User users = 1;
}
// Response of GET api/issues/authors