Browse Source

SONAR-8773 Move WS update_key and bulk_update_key to api/projects

tags/6.4-RC1
Teryk Bellahsene 7 years ago
parent
commit
da6b8dc9f8
21 changed files with 188 additions and 153 deletions
  1. 2
    2
      it/it-tests/src/test/java/it/Category4Suite.java
  2. 0
    37
      it/it-tests/src/test/java/it/component/ComponentsWsTest.java
  3. 52
    1
      it/it-tests/src/test/java/it/component/ProjectsWsTest.java
  4. 0
    2
      server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentsWsModule.java
  5. 28
    18
      server/sonar-server/src/main/java/org/sonar/server/project/ws/BulkUpdateKeyAction.java
  6. 2
    0
      server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsModule.java
  7. 21
    10
      server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateKeyAction.java
  8. 0
    0
      server/sonar-server/src/main/resources/org/sonar/server/project/ws/bulk_update_key-example.json
  9. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentsWsModuleTest.java
  10. 12
    12
      server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java
  11. 1
    1
      server/sonar-server/src/test/java/org/sonar/server/project/ws/ProjectsWsModuleTest.java
  12. 6
    5
      server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java
  13. 0
    28
      sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java
  14. 0
    8
      sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java
  15. 6
    5
      sonar-ws/src/main/java/org/sonarqube/ws/client/project/BulkUpdateKeyWsRequest.java
  16. 30
    4
      sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsService.java
  17. 7
    0
      sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsWsParameters.java
  18. 6
    5
      sonar-ws/src/main/java/org/sonarqube/ws/client/project/UpdateKeyWsRequest.java
  19. 0
    11
      sonar-ws/src/main/protobuf/ws-components.proto
  20. 10
    0
      sonar-ws/src/main/protobuf/ws-projects.proto
  21. 4
    3
      sonar-ws/src/test/java/org/sonarqube/ws/client/project/UpdateKeyWsRequestTest.java

+ 2
- 2
it/it-tests/src/test/java/it/Category4Suite.java View File

@@ -23,7 +23,7 @@ import com.sonar.orchestrator.Orchestrator;
import it.analysisExclusion.FileExclusionsTest;
import it.analysisExclusion.IssueExclusionsTest;
import it.component.ComponentsWsTest;
import it.component.ProjectSearchTest;
import it.component.ProjectsWsTest;
import it.dbCleaner.PurgeTest;
import it.duplication.CrossProjectDuplicationsOnRemoveFileTest;
import it.duplication.CrossProjectDuplicationsTest;
@@ -69,7 +69,7 @@ import static util.ItUtils.xooPlugin;
BaseIdentityProviderTest.class,
OAuth2IdentityProviderTest.class,
// component search
ProjectSearchTest.class,
ProjectsWsTest.class,
ComponentsWsTest.class,
// analysis exclusion
FileExclusionsTest.class,

+ 0
- 37
it/it-tests/src/test/java/it/component/ComponentsWsTest.java View File

@@ -28,12 +28,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonarqube.ws.WsComponents;
import org.sonarqube.ws.WsComponents.BulkUpdateKeyWsResponse.Key;
import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.component.BulkUpdateWsRequest;
import org.sonarqube.ws.client.component.SearchWsRequest;
import org.sonarqube.ws.client.component.ShowWsRequest;
import org.sonarqube.ws.client.component.UpdateWsRequest;
import util.ItUtils;

import static java.util.Collections.singletonList;
@@ -44,7 +41,6 @@ public class ComponentsWsTest {
@ClassRule
public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
private static final String FILE_KEY = "sample:src/main/xoo/sample/Sample.xoo";
private static final String PROJECT_KEY = "sample";

@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -76,37 +72,4 @@ public class ComponentsWsTest {
assertThat(response).isNotNull();
assertThat(response.getComponents(0).getKey()).isEqualTo(FILE_KEY);
}

@Test
public void update_key() {
String newProjectKey = "another_project_key";
WsComponents.Component project = wsClient.components().show(new ShowWsRequest().setKey(PROJECT_KEY)).getComponent();
assertThat(project.getKey()).isEqualTo(PROJECT_KEY);

wsClient.components().updateKey(UpdateWsRequest.builder()
.setKey(PROJECT_KEY)
.setNewKey(newProjectKey)
.build());

assertThat(wsClient.components().show(new ShowWsRequest().setId(project.getId())).getComponent().getKey()).isEqualTo(newProjectKey);
}

@Test
public void bulk_update_key() {
String newProjectKey = "another_project_key";
WsComponents.Component project = wsClient.components().show(new ShowWsRequest().setKey(PROJECT_KEY)).getComponent();
assertThat(project.getKey()).isEqualTo(PROJECT_KEY);

WsComponents.BulkUpdateKeyWsResponse result = wsClient.components().bulkUpdateKey(BulkUpdateWsRequest.builder()
.setKey(PROJECT_KEY)
.setFrom(PROJECT_KEY)
.setTo(newProjectKey)
.build());

assertThat(wsClient.components().show(new ShowWsRequest().setId(project.getId())).getComponent().getKey()).isEqualTo(newProjectKey);
assertThat(result.getKeysCount()).isEqualTo(1);
assertThat(result.getKeys(0))
.extracting(Key::getKey, Key::getNewKey, Key::getDuplicate)
.containsOnlyOnce(PROJECT_KEY, newProjectKey, false);
}
}

it/it-tests/src/test/java/it/component/ProjectSearchTest.java → it/it-tests/src/test/java/it/component/ProjectsWsTest.java View File

@@ -31,20 +31,38 @@ import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonarqube.ws.WsComponents;
import org.sonarqube.ws.WsProjects.BulkUpdateKeyWsResponse;
import org.sonarqube.ws.WsProjects.BulkUpdateKeyWsResponse.Key;
import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.component.ShowWsRequest;
import org.sonarqube.ws.client.project.BulkUpdateKeyWsRequest;
import org.sonarqube.ws.client.project.UpdateKeyWsRequest;
import util.ItUtils;

import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.projectDir;

public class ProjectSearchTest {
public class ProjectsWsTest {

@ClassRule
public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
private static final String PROJECT_KEY = "sample";

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

private WsClient wsClient;

@Before
public void inspectProject() {
orchestrator.resetData();
orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));

wsClient = ItUtils.newAdminWsClient(orchestrator);
}

/**
@@ -71,4 +89,37 @@ public class ProjectSearchTest {
httpclient.getConnectionManager().shutdown();
}
}

@Test
public void update_key() {
String newProjectKey = "another_project_key";
WsComponents.Component project = wsClient.components().show(new ShowWsRequest().setKey(PROJECT_KEY)).getComponent();
assertThat(project.getKey()).isEqualTo(PROJECT_KEY);

wsClient.projects().updateKey(UpdateKeyWsRequest.builder()
.setKey(PROJECT_KEY)
.setNewKey(newProjectKey)
.build());

assertThat(wsClient.components().show(new ShowWsRequest().setId(project.getId())).getComponent().getKey()).isEqualTo(newProjectKey);
}

@Test
public void bulk_update_key() {
String newProjectKey = "another_project_key";
WsComponents.Component project = wsClient.components().show(new ShowWsRequest().setKey(PROJECT_KEY)).getComponent();
assertThat(project.getKey()).isEqualTo(PROJECT_KEY);

BulkUpdateKeyWsResponse result = wsClient.projects().bulkUpdateKey(BulkUpdateKeyWsRequest.builder()
.setKey(PROJECT_KEY)
.setFrom(PROJECT_KEY)
.setTo(newProjectKey)
.build());

assertThat(wsClient.components().show(new ShowWsRequest().setId(project.getId())).getComponent().getKey()).isEqualTo(newProjectKey);
assertThat(result.getKeysCount()).isEqualTo(1);
assertThat(result.getKeys(0))
.extracting(Key::getKey, Key::getNewKey, Key::getDuplicate)
.containsOnlyOnce(PROJECT_KEY, newProjectKey, false);
}
}

+ 0
- 2
server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentsWsModule.java View File

@@ -33,8 +33,6 @@ public class ComponentsWsModule extends Module {
SuggestionsAction.class,
TreeAction.class,
ShowAction.class,
UpdateKeyAction.class,
BulkUpdateKeyAction.class,
SearchProjectsAction.class,
ProjectMeasuresQueryValidator.class);
}

server/sonar-server/src/main/java/org/sonar/server/component/ws/BulkUpdateKeyAction.java → server/sonar-server/src/main/java/org/sonar/server/project/ws/BulkUpdateKeyAction.java View File

@@ -17,10 +17,12 @@
* 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.ws;
package org.sonar.server.project.ws;

import com.google.common.collect.ImmutableList;
import java.util.Comparator;
import java.util.Map;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
@@ -33,22 +35,21 @@ import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.ComponentFinder.ParamNames;
import org.sonar.server.component.ComponentService;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsComponents;
import org.sonarqube.ws.WsComponents.BulkUpdateKeyWsResponse;
import org.sonarqube.ws.client.component.BulkUpdateWsRequest;
import org.sonarqube.ws.WsProjects.BulkUpdateKeyWsResponse;
import org.sonarqube.ws.client.project.BulkUpdateKeyWsRequest;

import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
import static org.sonar.db.component.ComponentKeyUpdaterDao.checkIsProjectOrModule;
import static org.sonar.server.ws.WsUtils.checkRequest;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_BULK_UPDATE_KEY;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_DRY_RUN;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FROM;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PROJECT;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_TO;
public class BulkUpdateKeyAction implements ComponentsWsAction {
import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_BULK_UPDATE_KEY;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_DRY_RUN;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_FROM;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_TO;
public class BulkUpdateKeyAction implements ProjectsWsAction {
private final DbClient dbClient;
private final ComponentFinder componentFinder;
private final ComponentKeyUpdaterDao componentKeyUpdater;
@@ -65,6 +66,10 @@ public class BulkUpdateKeyAction implements ComponentsWsAction {

@Override
public void define(WebService.NewController context) {
doDefine(context);
}

public WebService.NewAction doDefine(WebService.NewController context) {
WebService.NewAction action = context.createAction(ACTION_BULK_UPDATE_KEY)
.setDescription("Bulk update a project or module key and all its sub-components keys. " +
"The bulk update allows to replace a part of the current key by another string on the current project and all its sub-modules.<br>" +
@@ -89,6 +94,9 @@ public class BulkUpdateKeyAction implements ComponentsWsAction {
.setResponseExample(getClass().getResource("bulk_update_key-example.json"))
.setHandler(this);

action.setChangelog(
new Change("6.4", "Moved from api/components/bulk_update_key to api/projects/bulk_update_key"));

action.createParam(PARAM_PROJECT_ID)
.setDescription("Project or module ID")
.setDeprecatedKey("id", "6.4")
@@ -113,6 +121,8 @@ public class BulkUpdateKeyAction implements ComponentsWsAction {
.setDescription("Simulate bulk update. No component key is updated.")
.setBooleanPossibleValues()
.setDefaultValue(false);

return action;
}

@Override
@@ -120,7 +130,7 @@ public class BulkUpdateKeyAction implements ComponentsWsAction {
writeProtobuf(doHandle(toWsRequest(request)), request, response);
}

private BulkUpdateKeyWsResponse doHandle(BulkUpdateWsRequest request) {
private BulkUpdateKeyWsResponse doHandle(BulkUpdateKeyWsRequest request) {
DbSession dbSession = dbClient.openSession(false);
try {
ComponentDto projectOrModule = componentFinder.getByUuidOrKey(dbSession, request.getId(), request.getKey(), ParamNames.ID_AND_KEY);
@@ -145,17 +155,17 @@ public class BulkUpdateKeyAction implements ComponentsWsAction {
newKeysWithDuplicateMap.entrySet().forEach(entry -> checkRequest(!entry.getValue(), "Impossible to update key: a component with key \"%s\" already exists.", entry.getKey()));
}

private void bulkUpdateKey(DbSession dbSession, BulkUpdateWsRequest request, ComponentDto projectOrModule) {
private void bulkUpdateKey(DbSession dbSession, BulkUpdateKeyWsRequest request, ComponentDto projectOrModule) {
componentService.bulkUpdateKey(dbSession, projectOrModule.uuid(), request.getFrom(), request.getTo());
dbSession.commit();
}

private static BulkUpdateKeyWsResponse buildResponse(Map<String, String> newKeysByOldKeys, Map<String, Boolean> newKeysWithDuplicateMap) {
WsComponents.BulkUpdateKeyWsResponse.Builder response = WsComponents.BulkUpdateKeyWsResponse.newBuilder();
BulkUpdateKeyWsResponse.Builder response = BulkUpdateKeyWsResponse.newBuilder();

newKeysByOldKeys.entrySet().stream()
// sort by old key
.sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey()))
.sorted(Comparator.comparing(Map.Entry::getKey))
.forEach(
entry -> {
String newKey = entry.getValue();
@@ -168,8 +178,8 @@ public class BulkUpdateKeyAction implements ComponentsWsAction {
return response.build();
}

private static BulkUpdateWsRequest toWsRequest(Request request) {
return BulkUpdateWsRequest.builder()
private static BulkUpdateKeyWsRequest toWsRequest(Request request) {
return BulkUpdateKeyWsRequest.builder()
.setId(request.param(PARAM_PROJECT_ID))
.setKey(request.param(PARAM_PROJECT))
.setFrom(request.mandatoryParam(PARAM_FROM))

+ 2
- 0
server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsModule.java View File

@@ -31,6 +31,8 @@ public class ProjectsWsModule extends Module {
IndexAction.class,
BulkDeleteAction.class,
DeleteAction.class,
UpdateKeyAction.class,
BulkUpdateKeyAction.class,
GhostsAction.class,
ProvisionedAction.class,
SearchMyProjectsAction.class,

server/sonar-server/src/main/java/org/sonar/server/component/ws/UpdateKeyAction.java → server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateKeyAction.java View File

@@ -17,8 +17,10 @@
* 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.ws;

package org.sonar.server.project.ws;

import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
@@ -28,15 +30,15 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.ComponentFinder.ParamNames;
import org.sonar.server.component.ComponentService;
import org.sonarqube.ws.client.component.UpdateWsRequest;
import org.sonarqube.ws.client.project.UpdateKeyWsRequest;

import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_UPDATE_KEY;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_NEW_PROJECT;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PROJECT;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_UPDATE_KEY;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_NEW_PROJECT;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT_ID;

public class UpdateKeyAction implements ComponentsWsAction {
public class UpdateKeyAction implements ProjectsWsAction {
private final DbClient dbClient;
private final ComponentFinder componentFinder;
private final ComponentService componentService;
@@ -49,6 +51,10 @@ public class UpdateKeyAction implements ComponentsWsAction {

@Override
public void define(WebService.NewController context) {
doDefine(context);
}

public WebService.NewAction doDefine(WebService.NewController context) {
WebService.NewAction action = context.createAction(ACTION_UPDATE_KEY)
.setDescription("Update a project or module key and all its sub-components keys.<br>" +
"Either '%s' or '%s' must be provided, not both.<br> " +
@@ -62,6 +68,9 @@ public class UpdateKeyAction implements ComponentsWsAction {
.setPost(true)
.setHandler(this);

action.setChangelog(
new Change("6.4", "Move from api/components/update_key to api/projects/update_key"));

action.createParam(PARAM_PROJECT_ID)
.setDescription("Project or module id")
.setDeprecatedKey("id", "6.4")
@@ -77,6 +86,8 @@ public class UpdateKeyAction implements ComponentsWsAction {
.setRequired(true)
.setDeprecatedKey("newKey", "6.4")
.setExampleValue("my_new_project");

return action;
}

@Override
@@ -85,7 +96,7 @@ public class UpdateKeyAction implements ComponentsWsAction {
response.noContent();
}

private void doHandle(UpdateWsRequest request) {
private void doHandle(UpdateKeyWsRequest request) {
DbSession dbSession = dbClient.openSession(false);
try {
ComponentDto projectOrModule = componentFinder.getByUuidOrKey(dbSession, request.getId(), request.getKey(), ParamNames.PROJECT_ID_AND_PROJECT);
@@ -96,8 +107,8 @@ public class UpdateKeyAction implements ComponentsWsAction {
}
}

private static UpdateWsRequest toWsRequest(Request request) {
return UpdateWsRequest.builder()
private static UpdateKeyWsRequest toWsRequest(Request request) {
return UpdateKeyWsRequest.builder()
.setId(request.param(PARAM_PROJECT_ID))
.setKey(request.param(PARAM_PROJECT))
.setNewKey(request.mandatoryParam(PARAM_NEW_PROJECT))

server/sonar-server/src/main/resources/org/sonar/server/component/ws/bulk_update_key-example.json → server/sonar-server/src/main/resources/org/sonar/server/project/ws/bulk_update_key-example.json View File


+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentsWsModuleTest.java View File

@@ -30,6 +30,6 @@ public class ComponentsWsModuleTest {
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new ComponentsWsModule().configure(container);
assertThat(container.size()).isEqualTo(11 + COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER);
assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 9);
}
}

server/sonar-server/src/test/java/org/sonar/server/component/ws/BulkUpdateKeyActionTest.java → server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java View File

@@ -17,7 +17,8 @@
* 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.ws;

package org.sonar.server.project.ws;

import com.google.common.base.Throwables;
import java.io.IOException;
@@ -47,9 +48,8 @@ import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.WsComponents;
import org.sonarqube.ws.WsComponents.BulkUpdateKeyWsResponse;
import org.sonarqube.ws.WsComponents.BulkUpdateKeyWsResponse.Key;
import org.sonarqube.ws.WsProjects.BulkUpdateKeyWsResponse;
import org.sonarqube.ws.WsProjects.BulkUpdateKeyWsResponse.Key;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
@@ -61,11 +61,11 @@ import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_DRY_RUN;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FROM;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PROJECT;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_TO;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_DRY_RUN;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_FROM;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_TO;

public class BulkUpdateKeyActionTest {
private static final String MY_PROJECT_KEY = "my_project";
@@ -265,7 +265,7 @@ public class BulkUpdateKeyActionTest {
return componentDb.insertComponent(newProjectDto(db.organizations().insert()).setKey(MY_PROJECT_KEY));
}

private WsComponents.BulkUpdateKeyWsResponse callDryRunByUuid(@Nullable String uuid, @Nullable String from, @Nullable String to) {
private BulkUpdateKeyWsResponse callDryRunByUuid(@Nullable String uuid, @Nullable String from, @Nullable String to) {
return call(uuid, null, from, to, true);
}

@@ -273,7 +273,7 @@ public class BulkUpdateKeyActionTest {
return call(null, key, from, to, true);
}

private WsComponents.BulkUpdateKeyWsResponse callByUuid(@Nullable String uuid, @Nullable String from, @Nullable String to) {
private BulkUpdateKeyWsResponse callByUuid(@Nullable String uuid, @Nullable String from, @Nullable String to) {
return call(uuid, null, from, to, false);
}

@@ -302,7 +302,7 @@ public class BulkUpdateKeyActionTest {
}

try {
return WsComponents.BulkUpdateKeyWsResponse.parseFrom(request.execute().getInputStream());
return BulkUpdateKeyWsResponse.parseFrom(request.execute().getInputStream());
} catch (IOException e) {
throw Throwables.propagate(e);
}

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/project/ws/ProjectsWsModuleTest.java View File

@@ -30,6 +30,6 @@ public class ProjectsWsModuleTest {
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new ProjectsWsModule().configure(container);
assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 11);
assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 13);
}
}

server/sonar-server/src/test/java/org/sonar/server/component/ws/UpdateKeyActionTest.java → server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java View File

@@ -17,7 +17,8 @@
* 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.ws;

package org.sonar.server.project.ws;

import javax.annotation.Nullable;
import org.junit.Rule;
@@ -43,9 +44,9 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_NEW_PROJECT;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PROJECT;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_NEW_PROJECT;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT_ID;

public class UpdateKeyActionTest {
private static final String ANOTHER_KEY = "another_key";
@@ -58,7 +59,7 @@ public class UpdateKeyActionTest {

ComponentService componentService = mock(ComponentService.class);

WsActionTester ws = new WsActionTester(new UpdateKeyAction(dbClient, new ComponentFinder(dbClient), componentService));
WsActionTester ws = new WsActionTester(new org.sonar.server.project.ws.UpdateKeyAction(dbClient, new ComponentFinder(dbClient), componentService));

@Test
public void call_by_key() {

+ 0
- 28
sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java View File

@@ -21,35 +21,26 @@ package org.sonarqube.ws.client.component;

import com.google.common.base.Joiner;
import java.util.List;
import org.sonarqube.ws.WsComponents.BulkUpdateKeyWsResponse;
import org.sonarqube.ws.WsComponents.SearchProjectsWsResponse;
import org.sonarqube.ws.WsComponents.SearchWsResponse;
import org.sonarqube.ws.WsComponents.ShowWsResponse;
import org.sonarqube.ws.WsComponents.TreeWsResponse;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsConnector;

import static org.sonar.api.server.ws.WebService.Param;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_BULK_UPDATE_KEY;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SEARCH;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SEARCH_PROJECTS;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SHOW;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_TREE;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_UPDATE_KEY;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.CONTROLLER_COMPONENTS;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FROM;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_NEW_PROJECT;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PROJECT;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_STRATEGY;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_TO;

public class ComponentsService extends BaseService {

@@ -87,25 +78,6 @@ public class ComponentsService extends BaseService {
return call(get, ShowWsResponse.parser());
}

public void updateKey(UpdateWsRequest request) {
PostRequest post = new PostRequest(path(ACTION_UPDATE_KEY))
.setParam(PARAM_PROJECT_ID, request.getId())
.setParam(PARAM_PROJECT, request.getKey())
.setParam(PARAM_NEW_PROJECT, request.getNewKey());

call(post);
}

public BulkUpdateKeyWsResponse bulkUpdateKey(BulkUpdateWsRequest request) {
PostRequest post = new PostRequest(path(ACTION_BULK_UPDATE_KEY))
.setParam(PARAM_PROJECT_ID, request.getId())
.setParam(PARAM_PROJECT, request.getKey())
.setParam(PARAM_FROM, request.getFrom())
.setParam(PARAM_TO, request.getTo());

return call(post, BulkUpdateKeyWsResponse.parser());
}

public SearchProjectsWsResponse searchProjects(SearchProjectsRequest request) {
List<String> additionalFields = request.getAdditionalFields();
GetRequest get = new GetRequest(path(ACTION_SEARCH_PROJECTS))

+ 0
- 8
sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java View File

@@ -25,10 +25,8 @@ public class ComponentsWsParameters {

// actions
public static final String ACTION_SEARCH = "search";
public static final String ACTION_UPDATE_KEY = "update_key";
public static final String ACTION_TREE = "tree";
public static final String ACTION_SHOW = "show";
public static final String ACTION_BULK_UPDATE_KEY = "bulk_update_key";
public static final String ACTION_SEARCH_PROJECTS = "search_projects";
public static final String ACTION_SUGGESTIONS = "suggestions";

@@ -37,15 +35,9 @@ public class ComponentsWsParameters {
public static final String PARAM_QUALIFIERS = "qualifiers";
public static final String PARAM_LANGUAGE = "language";
public static final String PARAM_STRATEGY = "strategy";
public static final String PARAM_FROM = "from";
public static final String PARAM_TO = "to";
public static final String PARAM_DRY_RUN = "dryRun";
public static final String PARAM_FILTER = "filter";
public static final String PARAM_PROJECT_ID = "projectId";
public static final String PARAM_PROJECT = "project";
public static final String PARAM_COMPONENT_ID = "componentId";
public static final String PARAM_COMPONENT = "component";
public static final String PARAM_NEW_PROJECT = "newProject";

private ComponentsWsParameters() {
// static utility class

sonar-ws/src/main/java/org/sonarqube/ws/client/component/BulkUpdateWsRequest.java → sonar-ws/src/main/java/org/sonarqube/ws/client/project/BulkUpdateKeyWsRequest.java View File

@@ -17,7 +17,8 @@
* 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.component;

package org.sonarqube.ws.client.project;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -26,14 +27,14 @@ import javax.annotation.concurrent.Immutable;
import static com.google.common.base.Preconditions.checkArgument;

@Immutable
public class BulkUpdateWsRequest {
public class BulkUpdateKeyWsRequest {
private final String id;
private final String key;
private final String from;
private final String to;
private final boolean dryRun;

public BulkUpdateWsRequest(Builder builder) {
public BulkUpdateKeyWsRequest(Builder builder) {
this.id = builder.id;
this.key = builder.key;
this.from = builder.from;
@@ -103,10 +104,10 @@ public class BulkUpdateWsRequest {
return this;
}

public BulkUpdateWsRequest build() {
public BulkUpdateKeyWsRequest build() {
checkArgument(from != null && !from.isEmpty(), "The string to match must not be empty");
checkArgument(to != null && !to.isEmpty(), "The string replacement must not be empty");
return new BulkUpdateWsRequest(this);
return new BulkUpdateKeyWsRequest(this);
}
}
}

+ 30
- 4
sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsService.java View File

@@ -20,21 +20,28 @@
package org.sonarqube.ws.client.project;

import com.google.common.base.Joiner;
import org.sonarqube.ws.WsProjects;
import org.sonarqube.ws.WsProjects.BulkUpdateKeyWsResponse;
import org.sonarqube.ws.WsProjects.CreateWsResponse;
import org.sonarqube.ws.WsProjects.SearchWsResponse;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsConnector;

import static org.sonar.api.server.ws.WebService.Param.*;
import static org.sonar.api.server.ws.WebService.Param.PAGE;
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_BULK_UPDATE_KEY;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_CREATE;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_SEARCH;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.ACTION_UPDATE_KEY;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_BRANCH;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_NAME;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_NEW_PROJECT;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_ORGANIZATION;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_QUALIFIERS;

/**
@@ -70,13 +77,32 @@ public class ProjectsService extends BaseService {
.setParam("key", request.getKey()));
}

public WsProjects.SearchWsResponse search(SearchWsRequest request) {
public void updateKey(UpdateKeyWsRequest request) {
PostRequest post = new PostRequest(path(ACTION_UPDATE_KEY))
.setParam(PARAM_PROJECT_ID, request.getId())
.setParam(PARAM_PROJECT, request.getKey())
.setParam(PARAM_NEW_PROJECT, request.getNewKey());

call(post);
}

public BulkUpdateKeyWsResponse bulkUpdateKey(BulkUpdateKeyWsRequest request) {
PostRequest post = new PostRequest(path(ACTION_BULK_UPDATE_KEY))
.setParam(PARAM_PROJECT_ID, request.getId())
.setParam(PARAM_PROJECT, request.getKey())
.setParam(ProjectsWsParameters.PARAM_FROM, request.getFrom())
.setParam(ProjectsWsParameters.PARAM_TO, request.getTo());

return call(post, BulkUpdateKeyWsResponse.parser());
}

public SearchWsResponse search(SearchWsRequest request) {
GetRequest get = new GetRequest(path(ACTION_SEARCH))
.setParam(PARAM_ORGANIZATION, request.getOrganization())
.setParam(PARAM_QUALIFIERS, Joiner.on(",").join(request.getQualifiers()))
.setParam(TEXT_QUERY, request.getQuery())
.setParam(PAGE, request.getPage())
.setParam(PAGE_SIZE, request.getPageSize());
return call(get, WsProjects.SearchWsResponse.parser());
return call(get, SearchWsResponse.parser());
}
}

+ 7
- 0
sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsWsParameters.java View File

@@ -28,13 +28,20 @@ public class ProjectsWsParameters {
public static final String ACTION_CREATE = "create";
public static final String ACTION_INDEX = "index";
public static final String ACTION_SEARCH = "search";
public static final String ACTION_UPDATE_KEY = "update_key";
public static final String ACTION_BULK_UPDATE_KEY = "bulk_update_key";

public static final String PARAM_PROJECT = "project";
public static final String PARAM_PROJECT_ID = "projectId";
public static final String PARAM_NEW_PROJECT = "newProject";
public static final String PARAM_NAME = "name";
public static final String PARAM_BRANCH = "branch";
public static final String PARAM_ORGANIZATION = "organization";
public static final String PARAM_QUALIFIERS = "qualifiers";
public static final String PARAM_FROM = "from";
public static final String PARAM_TO = "to";
public static final String PARAM_DRY_RUN = "dryRun";


public static final String FILTER_LANGUAGE = "language";


sonar-ws/src/main/java/org/sonarqube/ws/client/component/UpdateWsRequest.java → sonar-ws/src/main/java/org/sonarqube/ws/client/project/UpdateKeyWsRequest.java View File

@@ -17,7 +17,8 @@
* 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.component;

package org.sonarqube.ws.client.project;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -26,12 +27,12 @@ import javax.annotation.concurrent.Immutable;
import static com.google.common.base.Preconditions.checkArgument;

@Immutable
public class UpdateWsRequest {
public class UpdateKeyWsRequest {
private final String id;
private final String key;
private final String newKey;

public UpdateWsRequest(Builder builder) {
public UpdateKeyWsRequest(Builder builder) {
this.id = builder.id;
this.key = builder.key;
this.newKey = builder.newKey;
@@ -79,9 +80,9 @@ public class UpdateWsRequest {
return this;
}

public UpdateWsRequest build() {
public UpdateKeyWsRequest build() {
checkArgument(newKey != null && !newKey.isEmpty(), "The new key must not be empty");
return new UpdateWsRequest(this);
return new UpdateKeyWsRequest(this);
}
}
}

+ 0
- 11
sonar-ws/src/main/protobuf/ws-components.proto View File

@@ -56,17 +56,6 @@ message SuggestionsWsResponse {
}
}

// WS api/components/prepare_bulk_update_key
message BulkUpdateKeyWsResponse {
repeated Key keys = 1;

message Key {
optional string key = 1;
optional string newKey = 2;
optional bool duplicate = 3;
}
}

// WS api/components/search_projects
message SearchProjectsWsResponse {
optional sonarqube.ws.commons.Paging paging = 1;

+ 10
- 0
sonar-ws/src/main/protobuf/ws-projects.proto View File

@@ -71,3 +71,13 @@ message SearchWsResponse {
}
}

// WS api/projects/prepare_bulk_update_key
message BulkUpdateKeyWsResponse {
repeated Key keys = 1;

message Key {
optional string key = 1;
optional string newKey = 2;
optional bool duplicate = 3;
}
}

sonar-ws/src/test/java/org/sonarqube/ws/client/component/UpdateWsRequestTest.java → sonar-ws/src/test/java/org/sonarqube/ws/client/project/UpdateKeyWsRequestTest.java View File

@@ -17,18 +17,19 @@
* 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.component;

package org.sonarqube.ws.client.project;

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

public class UpdateWsRequestTest {
public class UpdateKeyWsRequestTest {

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

UpdateWsRequest.Builder underTest = UpdateWsRequest.builder();
UpdateKeyWsRequest.Builder underTest = UpdateKeyWsRequest.builder();

@Test
public void fail_if_new_key_is_null() {

Loading…
Cancel
Save