diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-01-23 23:36:47 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-01-24 09:39:42 +0100 |
commit | 9f80575a9fcf9faf9aabaf91a6c649315e7c31a4 (patch) | |
tree | 61f83eab0029e67445c41f15850806a5b5b88521 /server | |
parent | d64a58b9177703e574f4214a7354b75407f61df8 (diff) | |
download | sonarqube-9f80575a9fcf9faf9aabaf91a6c649315e7c31a4.tar.gz sonarqube-9f80575a9fcf9faf9aabaf91a6c649315e7c31a4.zip |
Drop unused ResourceDao#findProvisionedProjects()
Diffstat (limited to 'server')
4 files changed, 2 insertions, 366 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentQuery.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentQuery.java deleted file mode 100644 index 8b39ab8f2d0..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentQuery.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.component; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.util.Collection; -import java.util.Collections; -import java.util.Set; - -/** - * @since 3.7 - */ -public class ComponentQuery { - - public static final int DEFAULT_PAGE_INDEX = 1; - public static final int DEFAULT_PAGE_SIZE = 100; - public static final int NO_PAGINATION = -1; - - public static final String SORT_BY_NAME = "NAME"; - public static final Set<String> SORTS = ImmutableSet.of(SORT_BY_NAME); - - private final Collection<String> keys; - private final Collection<String> names; - private final Collection<String> qualifiers; - private final String sort; - private final Boolean asc; - - // max results per page - private final int pageSize; - - // index of selected page. Start with 1. - private final int pageIndex; - - private ComponentQuery(Builder builder) { - this.keys = defaultCollection(builder.keys); - this.names = defaultCollection(builder.names); - this.qualifiers = defaultCollection(builder.qualifiers); - - this.sort = builder.sort; - this.asc = builder.asc; - this.pageSize = builder.pageSize; - this.pageIndex = builder.pageIndex; - } - - /** - * Pattern of component keys to search. Can contain a sub part of keys. - * Example : 'org.codehaus' will return 'org.codehaus.sonar', 'org.codehaus.tike', etc. - */ - public Collection<String> keys() { - return keys; - } - - /** - * Pattern of component name to search. Can contain a sub part of names. - * Example : 'Sona' will return 'Sonar', 'SonarJ', etc. - */ - public Collection<String> names() { - return names; - } - - /** - * Qualifiers of components to search. - */ - public Collection<String> qualifiers() { - return qualifiers; - } - - @CheckForNull - public String sort() { - return sort; - } - - @CheckForNull - public Boolean asc() { - return asc; - } - - public int pageSize() { - return pageSize; - } - - public int pageIndex() { - return pageIndex; - } - - @Override - public String toString() { - return ReflectionToStringBuilder.toString(this); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Collection<String> keys; - private Collection<String> names; - private Collection<String> qualifiers; - private String sort = SORT_BY_NAME; - private Boolean asc = true; - private Integer pageSize; - private Integer pageIndex; - - private Builder() { - } - - public Builder keys(@Nullable Collection<String> l) { - this.keys = l; - return this; - } - - public Builder names(@Nullable Collection<String> l) { - this.names = l; - return this; - } - - public Builder qualifiers(@Nullable Collection<String> l) { - this.qualifiers = l; - return this; - } - - public Builder sort(@Nullable String s) { - if (s != null && !SORTS.contains(s)) { - throw new IllegalArgumentException("Bad sort field: " + s); - } - this.sort = s; - return this; - } - - public Builder asc(@Nullable Boolean asc) { - this.asc = asc; - return this; - } - - public Builder pageSize(@Nullable Integer i) { - this.pageSize = i; - return this; - } - - public Builder pageIndex(@Nullable Integer i) { - this.pageIndex = i; - return this; - } - - public ComponentQuery build() { - initPageIndex(); - initPageSize(); - return new ComponentQuery(this); - } - - private void initPageSize() { - if (pageSize == null) { - pageSize = DEFAULT_PAGE_SIZE; - } - } - - private void initPageIndex() { - if (pageIndex == null) { - pageIndex = DEFAULT_PAGE_INDEX; - } - Preconditions.checkArgument(pageIndex > 0, "Page index must be greater than 0 (got " + pageIndex + ")"); - } - } - - private static <T> Collection<T> defaultCollection(@Nullable Collection<T> c) { - return c == null ? Collections.<T>emptyList() : Collections.unmodifiableCollection(c); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java b/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java index 5aad761f182..75cb463c396 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java @@ -19,9 +19,6 @@ */ package org.sonar.server.component; -import com.google.common.base.Strings; -import java.util.List; -import java.util.Map; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.component.Component; @@ -30,29 +27,24 @@ import org.sonar.api.resources.Qualifiers; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.ResourceDao; -import org.sonar.db.component.ResourceDto; import org.sonar.server.favorite.FavoriteUpdater; import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.permission.PermissionTemplateService; -import org.sonar.server.util.RubyUtils; import static org.sonar.server.component.NewComponent.newComponentBuilder; public class DefaultRubyComponentService implements RubyComponentService { private final DbClient dbClient; - private final ResourceDao resourceDao; private final ComponentService componentService; private final PermissionTemplateService permissionTemplateService; private final FavoriteUpdater favoriteUpdater; private final DefaultOrganizationProvider defaultOrganizationProvider; - public DefaultRubyComponentService(DbClient dbClient, ResourceDao resourceDao, ComponentService componentService, + public DefaultRubyComponentService(DbClient dbClient, ComponentService componentService, PermissionTemplateService permissionTemplateService, FavoriteUpdater favoriteUpdater, DefaultOrganizationProvider defaultOrganizationProvider) { this.dbClient = dbClient; - this.resourceDao = resourceDao; this.componentService = componentService; this.permissionTemplateService = permissionTemplateService; this.favoriteUpdater = favoriteUpdater; @@ -102,25 +94,4 @@ public class DefaultRubyComponentService implements RubyComponentService { return provisionedComponent.getId(); } - // Used in GOV - public List<ResourceDto> findProvisionedProjects(Map<String, Object> params) { - ComponentQuery query = toQuery(params); - return resourceDao.selectProvisionedProjects(query.qualifiers()); - } - - static ComponentQuery toQuery(Map<String, Object> props) { - ComponentQuery.Builder builder = ComponentQuery.builder() - .keys(RubyUtils.toStrings(props.get("keys"))) - .names(RubyUtils.toStrings(props.get("names"))) - .qualifiers(RubyUtils.toStrings(props.get("qualifiers"))) - .pageSize(RubyUtils.toInteger(props.get("pageSize"))) - .pageIndex(RubyUtils.toInteger(props.get("pageIndex"))); - String sort = (String) props.get("sort"); - if (!Strings.isNullOrEmpty(sort)) { - builder.sort(sort); - builder.asc(RubyUtils.toBoolean(props.get("asc"))); - } - return builder.build(); - } - } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentQueryTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentQueryTest.java deleted file mode 100644 index 0fffbd2f45b..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentQueryTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.component; - -import org.junit.Test; - -import static com.google.common.collect.Lists.newArrayList; -import static org.assertj.core.api.Assertions.assertThat; - -public class ComponentQueryTest { - - @Test - public void should_build_query() { - ComponentQuery query = ComponentQuery.builder() - .keys(newArrayList("org.codehaus")) - .names(newArrayList("Sona")) - .qualifiers(newArrayList("TRK")) - .pageSize(10) - .pageIndex(2) - .sort(ComponentQuery.SORT_BY_NAME) - .asc(true) - .build(); - assertThat(query.keys()).containsOnly("org.codehaus"); - assertThat(query.names()).containsOnly("Sona"); - assertThat(query.qualifiers()).containsOnly("TRK"); - assertThat(query.sort()).isEqualTo(ComponentQuery.SORT_BY_NAME); - assertThat(query.asc()).isTrue(); - assertThat(query.pageSize()).isEqualTo(10); - assertThat(query.pageIndex()).isEqualTo(2); - } - - @Test - public void should_accept_null_sort() { - ComponentQuery query = ComponentQuery.builder().sort(null).build(); - assertThat(query.sort()).isNull(); - } - - @Test - public void should_sort_by_name_asc_by_default() { - ComponentQuery query = ComponentQuery.builder().build(); - assertThat(query.sort()).isEqualTo(ComponentQuery.SORT_BY_NAME); - assertThat(query.asc()).isTrue(); - } - - @Test - public void should_throw_exception_if_sort_is_not_valid() { - try { - ComponentQuery.builder() - .sort("UNKNOWN") - .build(); - } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Bad sort field: UNKNOWN"); - } - } - - @Test - public void test_default_page_index_and_size() throws Exception { - ComponentQuery query = ComponentQuery.builder().build(); - assertThat(query.pageSize()).isEqualTo(ComponentQuery.DEFAULT_PAGE_SIZE); - assertThat(query.pageIndex()).isEqualTo(ComponentQuery.DEFAULT_PAGE_INDEX); - } - - @Test - public void should_build_non_paginated_query() { - ComponentQuery query = ComponentQuery.builder().pageSize(ComponentQuery.NO_PAGINATION).build(); - assertThat(query.pageSize()).isEqualTo(ComponentQuery.NO_PAGINATION); - assertThat(query.pageIndex()).isEqualTo(ComponentQuery.DEFAULT_PAGE_INDEX); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java index 46f0c39324f..1158499318a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java @@ -19,8 +19,6 @@ */ package org.sonar.server.component; -import java.util.List; -import java.util.Map; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -30,10 +28,8 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ResourceDao; -import org.sonar.db.component.ResourceDto; import org.sonar.server.component.index.ComponentIndexDefinition; import org.sonar.server.component.index.ComponentIndexer; import org.sonar.server.es.EsTester; @@ -47,8 +43,6 @@ import org.sonar.server.organization.TestDefaultOrganizationProvider; import org.sonar.server.permission.PermissionTemplateService; import org.sonar.server.tester.UserSessionRule; -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Maps.newHashMap; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; @@ -74,16 +68,13 @@ public class DefaultRubyComponentServiceTest { private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); - private ResourceDao resourceDao = dbClient.resourceDao(); private ComponentService componentService = new ComponentService(dbClient, i18n, userSession, system2, new ComponentFinder(dbClient), new ProjectMeasuresIndexer(system2, dbClient, es.client()), new ComponentIndexer(dbClient, es.client())); private PermissionTemplateService permissionTemplateService = mock(PermissionTemplateService.class); private FavoriteUpdater favoriteUpdater = mock(FavoriteUpdater.class); private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); - private ComponentDbTester componentDb = new ComponentDbTester(db); - - private DefaultRubyComponentService underTest = new DefaultRubyComponentService(dbClient, resourceDao, componentService, + private DefaultRubyComponentService underTest = new DefaultRubyComponentService(dbClient, componentService, permissionTemplateService, favoriteUpdater, defaultOrganizationProvider); private String defaultOrganizationUuid; @@ -118,53 +109,4 @@ public class DefaultRubyComponentServiceTest { underTest.createComponent("1234", "New Project", Qualifiers.PROJECT); } - @Test - public void should_find_provisioned_projects() { - componentDb.insertProject(); - List<String> qualifiers = newArrayList("TRK"); - Map<String, Object> map = newHashMap(); - map.put("qualifiers", qualifiers); - - List<ResourceDto> resourceDtos = underTest.findProvisionedProjects(map); - assertThat(resourceDtos).hasSize(1); - } - - @Test - public void should_create_query_from_parameters() { - Map<String, Object> map = newHashMap(); - map.put("keys", newArrayList("org.codehaus.sonar")); - map.put("names", newArrayList("Sonar")); - map.put("qualifiers", newArrayList("TRK")); - map.put("pageSize", 10l); - map.put("pageIndex", 50); - map.put("sort", "NAME"); - map.put("asc", true); - - ComponentQuery query = DefaultRubyComponentService.toQuery(map); - assertThat(query.keys()).containsOnly("org.codehaus.sonar"); - assertThat(query.names()).containsOnly("Sonar"); - assertThat(query.qualifiers()).containsOnly("TRK"); - assertThat(query.pageSize()).isEqualTo(10); - assertThat(query.pageIndex()).isEqualTo(50); - assertThat(query.sort()).isEqualTo(ComponentQuery.SORT_BY_NAME); - assertThat(query.asc()).isTrue(); - } - - @Test - public void should_create_query_with_default_paging_from_parameters() { - Map<String, Object> map = newHashMap(); - map.put("keys", newArrayList("org.codehaus.sonar")); - map.put("names", newArrayList("Sonar")); - map.put("qualifiers", newArrayList("TRK")); - - ComponentQuery query = DefaultRubyComponentService.toQuery(map); - assertThat(query.keys()).containsOnly("org.codehaus.sonar"); - assertThat(query.names()).containsOnly("Sonar"); - assertThat(query.qualifiers()).containsOnly("TRK"); - assertThat(query.pageSize()).isEqualTo(100); - assertThat(query.pageIndex()).isEqualTo(1); - assertThat(query.sort()).isEqualTo(ComponentQuery.SORT_BY_NAME); - assertThat(query.asc()).isTrue(); - } - } |