Selaa lähdekoodia

SONAR-8804 Use api/projects/search in projects admin page

tags/6.3.0.18587
Julien Lancelot 7 vuotta sitten
vanhempi
commit
caf680a416

+ 2
- 1
server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchAction.java Näytä tiedosto

@@ -44,6 +44,7 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.WsProjects.SearchWsResponse.Component;
import static org.sonarqube.ws.WsProjects.SearchWsResponse.newBuilder;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_SEARCH;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.MAX_PAGE_SIZE;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ORGANIZATION;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_QUALIFIERS;

@@ -68,7 +69,7 @@ public class SearchAction implements ProjectsWsAction {
.setDescription("Search for projects or views.<br>" +
"Requires 'System Administrator' permission")
.setInternal(true)
.addPagingParams(100)
.addPagingParams(100, MAX_PAGE_SIZE)
.addSearchQuery("sona", "component names", "component keys")
.setResponseExample(getClass().getResource("search-example.json"))
.setHandler(this);

+ 1
- 3
server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java Näytä tiedosto

@@ -24,7 +24,6 @@ import com.google.common.base.Throwables;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.Rule;
@@ -64,7 +63,6 @@ import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.MediaTypes.PROTOBUF;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ORGANIZATION;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_QUALIFIERS;

public class SearchActionTest {

@@ -253,7 +251,7 @@ public class SearchActionTest {
WebService.Param psParam = action.param("ps");
assertThat(psParam.isRequired()).isFalse();
assertThat(psParam.defaultValue()).isEqualTo("100");
assertThat(psParam.description()).isEqualTo("Page size. Must be greater than 0.");
assertThat(psParam.description()).isEqualTo("Page size. Must be greater than 0 and less than 500");
}

@Test

+ 1
- 1
server/sonar-web/src/main/js/api/components.js Näytä tiedosto

@@ -21,7 +21,7 @@
import { getJSON, postJSON, post } from '../helpers/request';

export function getComponents (data?: Object) {
const url = '/api/components/search';
const url = '/api/projects/search';
return getJSON(url, data);
}


+ 5
- 10
sonar-plugin-api/src/main/java/org/sonar/api/utils/Paging.java Näytä tiedosto

@@ -19,6 +19,8 @@
*/
package org.sonar.api.utils;

import static com.google.common.base.Preconditions.checkArgument;

/**
* @since 3.6
*/
@@ -29,16 +31,9 @@ public class Paging {
private final int total;

private Paging(int pageSize, int pageIndex, int total) {
if (pageSize < 1) {
throw new IllegalArgumentException("Page size must be strictly positive. Got " + pageSize);
}
if (pageIndex < 1) {
throw new IllegalArgumentException("Page index must be strictly positive. Got " + pageIndex);
}
if (total < 0) {
throw new IllegalArgumentException("Total items must be positive. Got " + total);
}

checkArgument(pageSize >= 1, "Page size must be strictly positive. Got %s", pageSize);
checkArgument(pageIndex >= 1, "Page index must be strictly positive. Got %s", pageIndex);
checkArgument(total >= 0, "Total items must be positive. Got %s", total);
this.pageSize = pageSize;
this.pageIndex = pageIndex;
this.total = total;

+ 2
- 0
sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsWsParameters.java Näytä tiedosto

@@ -21,6 +21,8 @@ package org.sonarqube.ws.client.project;

public class ProjectsWsParameters {

public static final int MAX_PAGE_SIZE = 500;

public static final String CONTROLLER = "api/projects";

public static final String ACTION_CREATE = "create";

+ 4
- 0
sonar-ws/src/main/java/org/sonarqube/ws/client/project/SearchWsRequest.java Näytä tiedosto

@@ -24,9 +24,12 @@ import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.MAX_PAGE_SIZE;

public class SearchWsRequest {

private final String organization;
private final String query;
private final List<String> qualifiers;
@@ -102,6 +105,7 @@ public class SearchWsRequest {
}

public SearchWsRequest build() {
checkArgument(pageSize == null || pageSize <= MAX_PAGE_SIZE, "Page size must not be greater than %s", MAX_PAGE_SIZE);
return new SearchWsRequest(this);
}
}

+ 60
- 0
sonar-ws/src/test/java/org/sonarqube/ws/client/project/SearchWsRequestTest.java Näytä tiedosto

@@ -0,0 +1,60 @@
/*
* 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.sonarqube.ws.client.project;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;

public class SearchWsRequestTest {

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Test
public void create_request() throws Exception {
SearchWsRequest underTest = SearchWsRequest.builder()
.setOrganization("orga")
.setQuery("project")
.setQualifiers(asList("TRK", "VW"))
.setPage(5)
.setPageSize(10)
.build();

assertThat(underTest.getOrganization()).isEqualTo("orga");
assertThat(underTest.getQuery()).isEqualTo("project");
assertThat(underTest.getQualifiers()).containsOnly("TRK", "VW");
assertThat(underTest.getPage()).isEqualTo(5);
assertThat(underTest.getPageSize()).isEqualTo(10);
}

@Test
public void fail_when_page_size_is_greather_then_500() throws Exception {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Page size must not be greater than 500");

SearchWsRequest.builder()
.setPageSize(10000)
.build();
}
}

Loading…
Peruuta
Tallenna