Search in sources :

Example 1 with UserDoc

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();
    }
}
Also used : OutputStream(java.io.OutputStream) UserDoc(org.sonar.server.user.index.UserDoc)

Example 2 with UserDoc

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()));
    }
}
Also used : Metric(org.sonar.server.issue.notification.NewIssuesStatistics.Metric) UserDoc(org.sonar.server.user.index.UserDoc)

Example 3 with UserDoc

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();
    }
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) SearchOptions(org.sonar.server.es.SearchOptions) JsonWriter(org.sonar.api.utils.text.JsonWriter) UserDoc(org.sonar.server.user.index.UserDoc)

Example 4 with UserDoc

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");
}
Also used : User(org.sonar.scanner.protocol.input.ScannerInput.User) WsTester(org.sonar.server.ws.WsTester) ByteArrayInputStream(java.io.ByteArrayInputStream) UserDoc(org.sonar.server.user.index.UserDoc) Test(org.junit.Test)

Example 5 with UserDoc

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");
}
Also used : UserDoc(org.sonar.server.user.index.UserDoc) Test(org.junit.Test)

Aggregations

UserDoc (org.sonar.server.user.index.UserDoc)13 Test (org.junit.Test)7 UserIndex (org.sonar.server.user.index.UserIndex)4 Before (org.junit.Before)3 UserDto (org.sonar.db.user.UserDto)3 Locale (java.util.Locale)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 EmailSettings (org.sonar.api.config.EmailSettings)2 DefaultI18n (org.sonar.core.i18n.DefaultI18n)2 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)2 WsTester (org.sonar.server.ws.WsTester)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 DbSession (org.sonar.db.DbSession)1 User (org.sonar.scanner.protocol.input.ScannerInput.User)1 ComponentFinder (org.sonar.server.component.ComponentFinder)1 SearchOptions (org.sonar.server.es.SearchOptions)1