use of org.sonar.server.user.index.UserDoc in project sonarqube by SonarSource.
the class UsersAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
List<String> logins = request.mandatoryParamAsStrings(PARAM_LOGINS);
response.stream().setMediaType(MediaTypes.PROTOBUF);
ScannerInput.User.Builder userBuilder = ScannerInput.User.newBuilder();
OutputStream output = response.stream().output();
try {
for (Iterator<UserDoc> userDocIterator = userIndex.selectUsersForBatch(logins); userDocIterator.hasNext(); ) {
handleUser(userDocIterator.next(), userBuilder, output);
}
} finally {
output.close();
}
}
use of org.sonar.server.user.index.UserDoc in project sonarqube by SonarSource.
the class NewIssuesNotification method setAssigneesStatistics.
protected void setAssigneesStatistics(NewIssuesStatistics.Stats stats) {
Metric metric = Metric.ASSIGNEE;
List<Multiset.Entry<String>> metricStats = stats.statsForMetric(metric);
for (int i = 0; i < 5 && i < metricStats.size(); i++) {
String login = metricStats.get(i).getElement();
UserDoc user = userIndex.getNullableByLogin(login);
String name = user == null ? login : user.name();
setFieldValue(metric + DOT + (i + 1) + LABEL, name);
setFieldValue(metric + DOT + (i + 1) + COUNT, String.valueOf(metricStats.get(i).getCount()));
}
}
use of org.sonar.server.user.index.UserDoc in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
SearchOptions options = new SearchOptions().setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE));
List<String> fields = request.paramAsStrings(Param.FIELDS);
SearchResult<UserDoc> result = userIndex.search(request.param(Param.TEXT_QUERY), options);
try (DbSession dbSession = dbClient.openSession(false)) {
List<String> logins = Lists.transform(result.getDocs(), UserDocToLogin.INSTANCE);
Multimap<String, String> groupsByLogin = dbClient.groupMembershipDao().selectGroupsByLogins(dbSession, logins);
Map<String, Integer> tokenCountsByLogin = dbClient.userTokenDao().countTokensByLogins(dbSession, logins);
JsonWriter json = response.newJsonWriter().beginObject();
options.writeJson(json, result.getTotal());
List<UserDto> userDtos = dbClient.userDao().selectByOrderedLogins(dbSession, logins);
writeUsers(json, userDtos, groupsByLogin, tokenCountsByLogin, fields);
json.endObject().close();
}
}
use of org.sonar.server.user.index.UserDoc in project sonarqube by SonarSource.
the class UsersActionTest method return_minimal_fields.
@Test
public void return_minimal_fields() throws Exception {
es.putDocuments(UserIndexDefinition.INDEX_TYPE_USER.getIndex(), UserIndexDefinition.INDEX_TYPE_USER.getType(), new UserDoc().setLogin("ada.lovelace").setName("Ada Lovelace").setActive(false), new UserDoc().setLogin("grace.hopper").setName("Grace Hopper").setActive(true));
userSessionRule.logIn("sonarqtech");
WsTester.TestRequest request = tester.newGetRequest("batch", "users").setParam("logins", "ada.lovelace,grace.hopper");
ByteArrayInputStream input = new ByteArrayInputStream(request.execute().output());
User user1 = User.parseDelimitedFrom(input);
User user2 = User.parseDelimitedFrom(input);
assertThat(User.parseDelimitedFrom(input)).isNull();
List<User> users = Arrays.asList(user1, user2);
assertThat(users).extracting("login").containsOnly("ada.lovelace", "grace.hopper");
assertThat(users).extracting("name").containsOnly("Ada Lovelace", "Grace Hopper");
}
use of org.sonar.server.user.index.UserDoc in project sonarqube by SonarSource.
the class DefaultAssigneeTest method default_assignee.
@Test
public void default_assignee() {
settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
when(userIndex.getNullableByLogin("erik")).thenReturn(new UserDoc().setLogin("erik").setActive(true));
assertThat(underTest.getLogin()).isEqualTo("erik");
}
Aggregations