+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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;
-
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.server.ServerSide;
-import org.sonar.server.issue.index.IssueIndex;
-
-@ServerSide
-@ComputeEngineSide
-public class IssueService {
-
- private final IssueIndex issueIndex;
-
- public IssueService(IssueIndex issueIndex) {
- this.issueIndex = issueIndex;
- }
-
- public List<String> listAuthors(@Nullable String textQuery, int pageSize) {
- IssueQuery query = IssueQuery.builder()
- .checkAuthorization(false)
- .build();
- return issueIndex.listAuthors(query, textQuery, pageSize);
- }
-
- public Map<String, Long> listTagsForComponent(IssueQuery query, int pageSize) {
- return issueIndex.countTags(query, pageSize);
- }
-
-}
package org.sonar.server.issue.ws;
import com.google.common.io.Resources;
+import java.util.List;
+import javax.annotation.Nullable;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.server.issue.IssueService;
+import org.sonar.server.issue.IssueQuery;
+import org.sonar.server.issue.index.IssueIndex;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.ACTION_AUTHORS;
public class AuthorsAction implements IssuesWsAction {
- private final IssueService service;
+ private final IssueIndex issueIndex;
- public AuthorsAction(IssueService service) {
- this.service = service;
+ public AuthorsAction(IssueIndex issueIndex) {
+ this.issueIndex = issueIndex;
}
@Override
.name("authors")
.beginArray();
- for (String login : service.listAuthors(query, pageSize)) {
+ for (String login : listAuthors(query, pageSize)) {
json.value(login);
}
json.endArray().endObject();
}
}
+
+ public List<String> listAuthors(@Nullable String textQuery, int pageSize) {
+ return issueIndex.listAuthors(IssueQuery.builder()
+ .checkAuthorization(false)
+ .build(), textQuery, pageSize);
+ }
}
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.server.issue.IssueQuery;
import org.sonar.server.issue.IssueQueryFactory;
-import org.sonar.server.issue.IssueService;
+import org.sonar.server.issue.index.IssueIndex;
import org.sonarqube.ws.client.issue.SearchWsRequest;
import static java.util.Collections.singletonList;
*/
public class ComponentTagsAction implements IssuesWsAction {
- private final IssueService service;
+ private final IssueIndex issueIndex;
private final IssueQueryFactory queryService;
- public ComponentTagsAction(IssueService service, IssueQueryFactory queryService) {
- this.service = service;
+ public ComponentTagsAction(IssueIndex issueIndex, IssueQueryFactory queryService) {
+ this.issueIndex = issueIndex;
this.queryService = queryService;
}
int pageSize = request.mandatoryParamAsInt(PAGE_SIZE);
try (JsonWriter json = response.newJsonWriter()) {
json.beginObject().name("tags").beginArray();
- for (Map.Entry<String, Long> tag : service.listTagsForComponent(query, pageSize).entrySet()) {
+ for (Map.Entry<String, Long> tag : issueIndex.countTags(query, pageSize).entrySet()) {
json.beginObject()
.prop("key", tag.getKey())
.prop("value", tag.getValue())
import org.sonar.server.issue.IssueFieldsSetter;
import org.sonar.server.issue.IssueFinder;
import org.sonar.server.issue.IssueQueryFactory;
-import org.sonar.server.issue.IssueService;
import org.sonar.server.issue.IssueUpdater;
import org.sonar.server.issue.ServerIssueStorage;
import org.sonar.server.issue.TransitionService;
IssueFieldsSetter.class,
FunctionExecutor.class,
IssueWorkflow.class,
- IssueService.class,
IssueQueryFactory.class,
IssuesWs.class,
AvatarResolverImpl.class,
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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;
-
-import com.google.common.collect.ImmutableSet;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.issue.Issue;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDao;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
-import org.sonar.db.issue.IssueDao;
-import org.sonar.db.issue.IssueDto;
-import org.sonar.db.issue.IssueTesting;
-import org.sonar.db.organization.OrganizationDao;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
-import org.sonar.db.rule.RuleDao;
-import org.sonar.db.rule.RuleDto;
-import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.issue.index.IssueIndex;
-import org.sonar.server.issue.index.IssueIndexer;
-import org.sonar.server.permission.index.PermissionIndexer;
-import org.sonar.server.rule.index.RuleIndexer;
-import org.sonar.server.tester.ServerTester;
-import org.sonar.server.tester.UserSessionRule;
-
-import static java.util.Arrays.asList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
-
-public class IssueServiceMediumTest {
-
- @ClassRule
- public static ServerTester tester = new ServerTester().withStartupTasks().withEsIndexes();
- @Rule
- public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
-
- private DbClient db = tester.get(DbClient.class);
- private IssueIndex issueIndex;
- private DbSession session;
- private IssueService service;
- private RuleIndexer ruleIndexer;
-
- @Before
- public void setUp() {
- tester.clearDbAndIndexes();
- issueIndex = tester.get(IssueIndex.class);
- session = db.openSession(false);
- service = tester.get(IssueService.class);
- ruleIndexer = tester.get(RuleIndexer.class);
- }
-
- @After
- public void after() {
- session.close();
- }
-
- @Test
- public void list_component_tags() {
- RuleDto rule = newRule();
- ComponentDto project = newPublicProject();
- ComponentDto file = newFile(project);
- saveIssue(IssueTesting.newDto(rule, file, project).setTags(ImmutableSet.of("convention", "java8", "bug")));
- saveIssue(IssueTesting.newDto(rule, file, project).setTags(ImmutableSet.of("convention", "bug")));
- saveIssue(IssueTesting.newDto(rule, file, project));
- saveIssue(IssueTesting.newDto(rule, file, project).setTags(ImmutableSet.of("convention", "java8", "bug")).setResolution(Issue.RESOLUTION_FIXED));
- saveIssue(IssueTesting.newDto(rule, file, project).setTags(ImmutableSet.of("convention")));
-
- assertThat(service.listTagsForComponent(projectQuery(project.uuid()), 5)).containsOnly(entry("convention", 3L), entry("bug", 2L), entry("java8", 1L));
- assertThat(service.listTagsForComponent(projectQuery(project.uuid()), 2)).contains(entry("convention", 3L), entry("bug", 2L)).doesNotContainEntry("java8", 1L);
- assertThat(service.listTagsForComponent(projectQuery("other"), 10)).isEmpty();
- }
-
- private IssueQuery projectQuery(String projectUuid) {
- return IssueQuery.builder().projectUuids(asList(projectUuid)).resolved(false).build();
- }
-
- @Test
- public void test_listAuthors() {
- RuleDto rule = newRule();
- ComponentDto project = newPublicProject();
- ComponentDto file = newFile(project);
- saveIssue(IssueTesting.newDto(rule, file, project).setAuthorLogin("luke.skywalker"));
- saveIssue(IssueTesting.newDto(rule, file, project).setAuthorLogin("luke@skywalker.name"));
- saveIssue(IssueTesting.newDto(rule, file, project));
- saveIssue(IssueTesting.newDto(rule, file, project).setAuthorLogin("anakin@skywalker.name"));
-
- assertThat(service.listAuthors(null, 5)).containsExactly("anakin@skywalker.name", "luke.skywalker", "luke@skywalker.name");
- assertThat(service.listAuthors(null, 2)).containsExactly("anakin@skywalker.name", "luke.skywalker");
- assertThat(service.listAuthors("uke", 5)).containsExactly("luke.skywalker", "luke@skywalker.name");
- assertThat(service.listAuthors(null, 1)).containsExactly("anakin@skywalker.name");
- assertThat(service.listAuthors(null, Integer.MAX_VALUE)).containsExactly("anakin@skywalker.name", "luke.skywalker", "luke@skywalker.name");
- }
-
- @Test
- public void listAuthors_escapes_regexp_special_characters() {
- saveIssue(IssueTesting.newDto(newRule(), newFile(newPublicProject()), newPublicProject()).setAuthorLogin("name++"));
-
- assertThat(service.listAuthors("invalidRegexp[", 5)).isEmpty();
- assertThat(service.listAuthors("nam+", 5)).isEmpty();
- assertThat(service.listAuthors("name+", 5)).containsExactly("name++");
- assertThat(service.listAuthors(".*", 5)).isEmpty();
- }
-
- private RuleDto newRule() {
- return newRule(RuleTesting.newXooX1());
- }
-
- private RuleDto newRule(RuleDto rule) {
- RuleDao ruleDao = tester.get(RuleDao.class);
- ruleDao.insert(session, rule.getDefinition());
- if (rule.getOrganizationUuid() != null) {
- ruleDao.insertOrUpdate(session, rule.getMetadata().setRuleId(rule.getId()));
- }
- session.commit();
- //FIXME ruleIndexer.commitAndIndex(dbSession, rule.getDefinition().getKey());
- return rule;
- }
-
- private ComponentDto newPublicProject() {
- OrganizationDto organization = OrganizationTesting.newOrganizationDto();
- tester.get(OrganizationDao.class).insert(session, organization, false);
- ComponentDto project = ComponentTesting.newPublicProjectDto(organization);
- tester.get(ComponentDao.class).insert(session, project);
- session.commit();
-
- indexPermissions();
- userSessionRule.logIn();
-
- return project;
- }
-
- private void indexPermissions() {
- PermissionIndexer permissionIndexer = tester.get(PermissionIndexer.class);
- permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes());
- }
-
- private ComponentDto newFile(ComponentDto project) {
- ComponentDto file = ComponentTesting.newFileDto(project, null);
- tester.get(ComponentDao.class).insert(session, file);
- session.commit();
- return file;
- }
-
- private IssueDto saveIssue(IssueDto issue) {
- tester.get(IssueDao.class).insert(session, issue);
- session.commit();
- tester.get(IssueIndexer.class).commitAndIndexIssues(session, asList(issue));
- return issue;
- }
-}
*/
package org.sonar.server.issue.index;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterators;
import java.util.ArrayList;
underTest.listTags(organization, null, 501);
}
+ @Test
+ public void test_listAuthors() {
+ OrganizationDto org = newOrganizationDto();
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(org);
+ indexIssues(
+ newDoc("issue1", project).setAuthorLogin("luke.skywalker"),
+ newDoc("issue2", project).setAuthorLogin("luke@skywalker.name"),
+ newDoc("issue3", project).setAuthorLogin(null),
+ newDoc("issue4", project).setAuthorLogin("anakin@skywalker.name"));
+ IssueQuery query = IssueQuery.builder()
+ .checkAuthorization(false)
+ .build();
+
+ assertThat(underTest.listAuthors(query, null, 5)).containsExactly("anakin@skywalker.name", "luke.skywalker", "luke@skywalker.name");
+ assertThat(underTest.listAuthors(query, null, 2)).containsExactly("anakin@skywalker.name", "luke.skywalker");
+ assertThat(underTest.listAuthors(query, "uke", 5)).containsExactly("luke.skywalker", "luke@skywalker.name");
+ assertThat(underTest.listAuthors(query, null, 1)).containsExactly("anakin@skywalker.name");
+ assertThat(underTest.listAuthors(query, null, Integer.MAX_VALUE)).containsExactly("anakin@skywalker.name", "luke.skywalker", "luke@skywalker.name");
+ }
+
+ @Test
+ public void listAuthors_escapes_regexp_special_characters() {
+ OrganizationDto org = newOrganizationDto();
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(org);
+ indexIssues(
+ newDoc("issue1", project).setAuthorLogin("name++"));
+ IssueQuery query = IssueQuery.builder()
+ .checkAuthorization(false)
+ .build();
+
+ assertThat(underTest.listAuthors(query, "invalidRegexp[", 5)).isEmpty();
+ assertThat(underTest.listAuthors(query, "nam+", 5)).isEmpty();
+ assertThat(underTest.listAuthors(query, "name+", 5)).containsExactly("name++");
+ assertThat(underTest.listAuthors(query, ".*", 5)).isEmpty();
+ }
+
@Test
public void filter_by_organization() {
OrganizationDto org1 = newOrganizationDto();
assertThatSearchReturnsEmpty(query);
}
+ @Test
+ public void countTags() {
+ OrganizationDto org = newOrganizationDto();
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(org);
+ indexIssues(
+ newDoc("issue1", project).setTags(ImmutableSet.of("convention", "java8", "bug")),
+ newDoc("issue2", project).setTags(ImmutableSet.of("convention", "bug")),
+ newDoc("issue3", project).setTags(emptyList()),
+ newDoc("issue4", project).setTags(ImmutableSet.of("convention", "java8", "bug")).setResolution(Issue.RESOLUTION_FIXED),
+ newDoc("issue5", project).setTags(ImmutableSet.of("convention"))
+ );
+
+ assertThat(underTest.countTags(projectQuery(project.uuid()), 5)).containsOnly(entry("convention", 3L), entry("bug", 2L), entry("java8", 1L));
+ assertThat(underTest.countTags(projectQuery(project.uuid()), 2)).contains(entry("convention", 3L), entry("bug", 2L)).doesNotContainEntry("java8", 1L);
+ assertThat(underTest.countTags(projectQuery("other"), 10)).isEmpty();
+ }
+
+ private IssueQuery projectQuery(String projectUuid) {
+ return IssueQuery.builder().projectUuids(singletonList(projectUuid)).resolved(false).build();
+ }
+
private void verifyOrganizationFilter(String organizationUuid, String... expectedIssueKeys) {
IssueQuery.Builder query = IssueQuery.builder().organizationUuid(organizationUuid);
assertThatSearchReturnsOnly(query, expectedIssueKeys);
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.server.es.EsTester;
-import org.sonar.server.issue.IssueService;
import org.sonar.server.issue.index.IssueIndex;
import org.sonar.server.issue.index.IssueIndexDefinition;
import org.sonar.server.issue.index.IssueIndexer;
private IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()));
private IssueIndex issueIndex = new IssueIndex(es.client(), System2.INSTANCE, userSession, new AuthorizationTypeSupport(userSession));
- private IssueService issueService = new IssueService(issueIndex);
- private WsActionTester ws = new WsActionTester(new AuthorsAction(issueService));
+ private WsActionTester ws = new WsActionTester(new AuthorsAction(issueIndex));
@Test
public void json_example() {
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.server.issue.IssueQuery;
import org.sonar.server.issue.IssueQueryFactory;
-import org.sonar.server.issue.IssueService;
+import org.sonar.server.issue.index.IssueIndex;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
import org.sonarqube.ws.client.issue.SearchWsRequest;
public class ComponentTagsActionTest {
- private IssueService service = mock(IssueService.class);
+ private IssueIndex service = mock(IssueIndex.class);
private IssueQueryFactory issueQueryFactory = mock(IssueQueryFactory.class, Mockito.RETURNS_DEEP_STUBS);
private ComponentTagsAction underTest = new ComponentTagsAction(service, issueQueryFactory);
private WsActionTester tester = new WsActionTester(underTest);
.build();
ArgumentCaptor<SearchWsRequest> captor = ArgumentCaptor.forClass(SearchWsRequest.class);
when(issueQueryFactory.create(captor.capture())).thenReturn(mock(IssueQuery.class));
- when(service.listTagsForComponent(any(IssueQuery.class), eq(5))).thenReturn(tags);
+ when(service.countTags(any(IssueQuery.class), eq(5))).thenReturn(tags);
TestResponse response = tester.newRequest()
.setParam("componentUuid", "polop")
.build();
ArgumentCaptor<SearchWsRequest> captor = ArgumentCaptor.forClass(SearchWsRequest.class);
when(issueQueryFactory.create(captor.capture())).thenReturn(mock(IssueQuery.class));
- when(service.listTagsForComponent(any(IssueQuery.class), eq(5))).thenReturn(tags);
+ when(service.countTags(any(IssueQuery.class), eq(5))).thenReturn(tags);
String componentUuid = "polop";
String createdAfter = "2011-04-25";
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new IssueWsModule().configure(container);
- assertThat(container.size()).isEqualTo(2 + 30);
+ assertThat(container.size()).isEqualTo(2 + 29);
}
}