diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-08-03 17:45:37 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-08-05 14:46:58 +0200 |
commit | 000f6b88a4cb60410a2bad5ef976bb783b3c7ba9 (patch) | |
tree | 6aa0f8f94bf11d82beed50ac7d38a833455a35f0 /sonar-ws | |
parent | 645d874eda971f79a0927aa6370adb9489f148b7 (diff) | |
download | sonarqube-000f6b88a4cb60410a2bad5ef976bb783b3c7ba9.tar.gz sonarqube-000f6b88a4cb60410a2bad5ef976bb783b3c7ba9.zip |
SONAR-7929 Create WS api/components/bulk_update_key
Diffstat (limited to 'sonar-ws')
4 files changed, 138 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/BulkUpdateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/BulkUpdateWsRequest.java new file mode 100644 index 00000000000..881a8d0fe1a --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/BulkUpdateWsRequest.java @@ -0,0 +1,111 @@ +/* + * 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.sonarqube.ws.client.component; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +import static com.google.common.base.Preconditions.checkArgument; + +public class BulkUpdateWsRequest { + private final String id; + private final String key; + private final String from; + private final String to; + private final boolean dryRun; + + public BulkUpdateWsRequest(Builder builder) { + this.id = builder.id; + this.key = builder.key; + this.from = builder.from; + this.to = builder.to; + this.dryRun = builder.dryRun; + } + + @CheckForNull + public String getId() { + return id; + } + + @CheckForNull + public String getKey() { + return key; + } + + public String getFrom() { + return from; + } + + public String getTo() { + return to; + } + + public boolean isDryRun() { + return dryRun; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String id; + private String key; + private String from; + private String to; + private boolean dryRun; + + private Builder() { + // enforce method constructor + } + + public Builder setId(@Nullable String id) { + this.id = id; + return this; + } + + public Builder setKey(@Nullable String key) { + this.key = key; + return this; + } + + public Builder setFrom(String from) { + this.from = from; + return this; + } + + public Builder setTo(String to) { + this.to = to; + return this; + } + + public Builder setDryRun(boolean dryRun) { + this.dryRun = dryRun; + return this; + } + + public BulkUpdateWsRequest 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); + } + } +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java index ffcbe8715ed..b7e71d43a3e 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java @@ -20,6 +20,7 @@ package org.sonarqube.ws.client.component; import com.google.common.base.Joiner; +import org.sonarqube.ws.WsComponents.BulkUpdateKeyWsResponse; import org.sonarqube.ws.WsComponents.SearchWsResponse; import org.sonarqube.ws.WsComponents.ShowWsResponse; import org.sonarqube.ws.WsComponents.TreeWsResponse; @@ -32,11 +33,13 @@ import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SH import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_TREE; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_ID; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_KEY; +import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FROM; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ID; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_KEY; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_NEW_KEY; 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 { @@ -81,4 +84,14 @@ public class ComponentsService extends BaseService { call(post); } + + public BulkUpdateKeyWsResponse bulkUpdateKey(BulkUpdateWsRequest request) { + PostRequest post = new PostRequest(path("bulk_update_key")) + .setParam(PARAM_ID, request.getId()) + .setParam(PARAM_KEY, request.getKey()) + .setParam(PARAM_FROM, request.getFrom()) + .setParam(PARAM_TO, request.getTo()); + + return call(post, BulkUpdateKeyWsResponse.parser()); + } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java index 456b46985a4..4ae95bf46b0 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java @@ -34,6 +34,9 @@ public class ComponentsWsParameters { public static final String PARAM_ID = "id"; public static final String PARAM_KEY = "key"; public static final String PARAM_NEW_KEY = "newKey"; + public static final String PARAM_FROM = "from"; + public static final String PARAM_TO = "to"; + public static final String PARAM_DRY_RUN = "dryRun"; private ComponentsWsParameters() { // static utility class diff --git a/sonar-ws/src/main/protobuf/ws-components.proto b/sonar-ws/src/main/protobuf/ws-components.proto index 128ade44c99..a14966e8acd 100644 --- a/sonar-ws/src/main/protobuf/ws-components.proto +++ b/sonar-ws/src/main/protobuf/ws-components.proto @@ -46,6 +46,17 @@ message ShowWsResponse { repeated Component ancestors = 3; } +// 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; + } +} + message Component { optional string id = 1; optional string key = 2; |