diff options
Diffstat (limited to 'sonar-ws/src/main')
4 files changed, 177 insertions, 3 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java index c6c39285761..333287250bb 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java @@ -19,27 +19,34 @@ */ package org.sonarqube.ws.client.measure; +import org.sonar.api.server.ws.WebService.Param; import org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse; import org.sonarqube.ws.WsMeasures.ComponentWsResponse; +import org.sonarqube.ws.WsMeasures.SearchHistoryResponse; import org.sonarqube.ws.client.BaseService; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsConnector; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT_TREE; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_SEARCH_HISTORY; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.CONTROLLER_MEASURES; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_ID; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_KEY; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_ID; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_KEY; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_FROM; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRICS; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_TO; public class MeasuresService extends BaseService { public MeasuresService(WsConnector wsConnector) { @@ -78,4 +85,16 @@ public class MeasuresService extends BaseService { return call(getRequest, ComponentWsResponse.parser()); } + + public SearchHistoryResponse searchHistory(SearchHistoryRequest request) { + GetRequest getRequest = new GetRequest(path(ACTION_SEARCH_HISTORY)) + .setParam(PARAM_COMPONENT, request.getComponent()) + .setParam(PARAM_METRICS, inlineMultipleParamValue(request.getMetrics())) + .setParam(PARAM_FROM, request.getFrom()) + .setParam(PARAM_TO, request.getTo()) + .setParam(Param.PAGE, request.getPage()) + .setParam(Param.PAGE_SIZE, request.getPageSize()); + + return call(getRequest, SearchHistoryResponse.parser()); + } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java index f83b5427f65..9625fa8f491 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java @@ -28,14 +28,16 @@ public class MeasuresWsParameters { // actions public static final String ACTION_COMPONENT_TREE = "component_tree"; - public static final String ACTION_COMPONENT = "component"; + public static final String ACTION_SEARCH_HISTORY = "search_history"; + // parameters public static final String PARAM_BASE_COMPONENT_ID = "baseComponentId"; - public static final String PARAM_BASE_COMPONENT_KEY = "baseComponentKey"; + public static final String PARAM_COMPONENT = "component"; public static final String PARAM_STRATEGY = "strategy"; public static final String PARAM_QUALIFIERS = "qualifiers"; + public static final String PARAM_METRICS = "metrics"; public static final String PARAM_METRIC_KEYS = "metricKeys"; public static final String PARAM_METRIC_SORT = "metricSort"; public static final String PARAM_METRIC_PERIOD_SORT = "metricPeriodSort"; @@ -46,9 +48,12 @@ public class MeasuresWsParameters { public static final String PARAM_PROJECT_KEYS = "projectKeys"; public static final String PARAM_DEVELOPER_ID = "developerId"; public static final String PARAM_DEVELOPER_KEY = "developerKey"; - public static final String ADDITIONAL_METRICS = "metrics"; + public static final String PARAM_FROM = "from"; + public static final String PARAM_TO = "to"; + public static final String ADDITIONAL_METRICS = "metrics"; public static final String ADDITIONAL_PERIODS = "periods"; + public static final Set<String> ADDITIONAL_FIELDS = ImmutableSortedSet.of(ADDITIONAL_METRICS, ADDITIONAL_PERIODS); private MeasuresWsParameters() { diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/SearchHistoryRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/SearchHistoryRequest.java new file mode 100644 index 00000000000..890229b1fff --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/SearchHistoryRequest.java @@ -0,0 +1,134 @@ +/* + * 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.measure; + +import java.util.List; +import javax.annotation.CheckForNull; + +import static java.lang.String.format; + +public class SearchHistoryRequest { + public static final int MAX_PAGE_SIZE = 1_000; + public static final int DEFAULT_PAGE_SIZE = 100; + + private final String component; + private final List<String> metrics; + private final String from; + private final String to; + private final int page; + private final int pageSize; + + public SearchHistoryRequest(Builder builder) { + this.component = builder.component; + this.metrics = builder.metrics; + this.from = builder.from; + this.to = builder.to; + this.page = builder.page; + this.pageSize = builder.pageSize; + } + + public String getComponent() { + return component; + } + + public List<String> getMetrics() { + return metrics; + } + + @CheckForNull + public String getFrom() { + return from; + } + + @CheckForNull + public String getTo() { + return to; + } + + public int getPage() { + return page; + } + + public int getPageSize() { + return pageSize; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String component; + private List<String> metrics; + private String from; + private String to; + private int page = 1; + private int pageSize = DEFAULT_PAGE_SIZE; + + private Builder() { + // enforce build factory method + } + + public Builder setComponent(String component) { + this.component = component; + return this; + } + + public Builder setMetrics(List<String> metrics) { + this.metrics = metrics; + return this; + } + + public Builder setFrom(String from) { + this.from = from; + return this; + } + + public Builder setTo(String to) { + this.to = to; + return this; + } + + public Builder setPage(int page) { + this.page = page; + return this; + } + + public Builder setPageSize(int pageSize) { + this.pageSize = pageSize; + return this; + } + + public SearchHistoryRequest build() { + checkArgument(component != null && !component.isEmpty(), "Component key is required"); + checkArgument(metrics != null && !metrics.isEmpty(), "Metric keys are required"); + checkArgument(pageSize <= MAX_PAGE_SIZE, "Page size (%d) must be lower than or equal to %d", pageSize, MAX_PAGE_SIZE); + + return new SearchHistoryRequest(this); + } + + private static void checkArgument(boolean condition, String message, Object... args) { + if (!condition) { + throw new IllegalArgumentException(format(message, args)); + } + } + } +} diff --git a/sonar-ws/src/main/protobuf/ws-measures.proto b/sonar-ws/src/main/protobuf/ws-measures.proto index 3636436de74..4c64b51ba47 100644 --- a/sonar-ws/src/main/protobuf/ws-measures.proto +++ b/sonar-ws/src/main/protobuf/ws-measures.proto @@ -47,6 +47,22 @@ message SearchWsResponse { repeated Measure measures = 1; } +// WS api/measures/search_history +message SearchHistoryResponse { + optional sonarqube.ws.commons.Paging paging = 1; + repeated HistoryMeasure measures = 2; + + message HistoryMeasure { + optional string metric = 1; + repeated HistoryValue history = 2; + } + + message HistoryValue { + optional string date = 1; + optional string value = 2; + } +} + message Component { optional string id = 1; optional string key = 2; |