@@ -65,11 +65,6 @@ public class FillComponentIssuesVisitorRule extends TypeAwareVisitorAdapter impl | |||
}; | |||
} | |||
public void setIssues(Component component, DefaultIssue... issues) { | |||
checkNotNull(component, "component cannot be null"); | |||
setIssues(component.getReportAttributes().getRef(), issues); | |||
} | |||
public void setIssues(int componentRef, DefaultIssue... issues) { | |||
Component component = treeRootHolder.getComponentByRef(componentRef); | |||
checkArgument(component != null, String.format("Component '%s' does not exists in the report ", componentRef)); |
@@ -76,7 +76,7 @@ import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createAddi | |||
import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createDeveloperParameters; | |||
import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createMetricKeysParameter; | |||
import static org.sonar.server.measure.ws.MetricDtoToWsMetric.metricDtoToWsMetric; | |||
import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriods.snapshotToWsPeriods; | |||
import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeriods; | |||
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; | |||
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; | |||
import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; | |||
@@ -154,10 +154,10 @@ public class ComponentAction implements MeasuresWsAction { | |||
checkPermissions(component); | |||
SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.projectUuid()).orElse(null); | |||
List<MetricDto> metrics = searchMetrics(dbSession, request); | |||
List<Measures.Period> periods = snapshotToWsPeriods(analysis); | |||
Optional<Measures.Period> period = snapshotToWsPeriods(analysis); | |||
List<LiveMeasureDto> measures = searchMeasures(dbSession, component, metrics); | |||
return buildResponse(request, component, refComponent, measures, metrics, periods); | |||
return buildResponse(request, component, refComponent, measures, metrics, period); | |||
} | |||
} | |||
@@ -183,8 +183,8 @@ public class ComponentAction implements MeasuresWsAction { | |||
return dbClient.componentDao().selectByUuid(dbSession, component.getCopyResourceUuid()); | |||
} | |||
private static ComponentWsResponse buildResponse(ComponentRequest request, ComponentDto component, Optional<ComponentDto> refComponent, List<LiveMeasureDto> measures, | |||
List<MetricDto> metrics, List<Measures.Period> periods) { | |||
private static ComponentWsResponse buildResponse(ComponentRequest request, ComponentDto component, Optional<ComponentDto> refComponent, | |||
List<LiveMeasureDto> measures, List<MetricDto> metrics, Optional<Measures.Period> period) { | |||
ComponentWsResponse.Builder response = ComponentWsResponse.newBuilder(); | |||
Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId); | |||
Map<MetricDto, LiveMeasureDto> measuresByMetric = new HashMap<>(); | |||
@@ -205,8 +205,8 @@ public class ComponentAction implements MeasuresWsAction { | |||
response.getMetricsBuilder().addMetrics(metricDtoToWsMetric(metric)); | |||
} | |||
} | |||
if (additionalFields.contains(ADDITIONAL_PERIODS)) { | |||
response.getPeriodsBuilder().addAllPeriods(periods); | |||
if (additionalFields.contains(ADDITIONAL_PERIODS) && period.isPresent()) { | |||
response.getPeriodsBuilder().addPeriods(period.get()); | |||
} | |||
} | |||
@@ -282,8 +282,6 @@ public class ComponentAction implements MeasuresWsAction { | |||
private String pullRequest; | |||
private List<String> metricKeys; | |||
private List<String> additionalFields; | |||
private String developerId; | |||
private String developerKey; | |||
/** | |||
* @deprecated since 6.6, please use {@link #getComponent()} instead | |||
@@ -351,25 +349,5 @@ public class ComponentAction implements MeasuresWsAction { | |||
this.additionalFields = additionalFields; | |||
return this; | |||
} | |||
@CheckForNull | |||
private String getDeveloperId() { | |||
return developerId; | |||
} | |||
private ComponentRequest setDeveloperId(@Nullable String developerId) { | |||
this.developerId = developerId; | |||
return this; | |||
} | |||
@CheckForNull | |||
private String getDeveloperKey() { | |||
return developerKey; | |||
} | |||
private ComponentRequest setDeveloperKey(@Nullable String developerKey) { | |||
this.developerKey = developerKey; | |||
return this; | |||
} | |||
} | |||
} |
@@ -107,12 +107,12 @@ import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createAddi | |||
import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createDeveloperParameters; | |||
import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createMetricKeysParameter; | |||
import static org.sonar.server.measure.ws.MetricDtoToWsMetric.metricDtoToWsMetric; | |||
import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriods.snapshotToWsPeriods; | |||
import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeriods; | |||
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; | |||
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; | |||
import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; | |||
import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; | |||
import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; | |||
import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; | |||
import static org.sonar.server.ws.WsUtils.checkRequest; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
@@ -121,15 +121,15 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
* To limit the number of rows in database, a best value algorithm exists in database.</p> | |||
* A measure is not stored in database if: | |||
* <ul> | |||
* <li>the component is a file (production or test)</li> | |||
* <li>optimization algorithm is enabled on the metric</li> | |||
* <li>the measure computed equals the metric best value</li> | |||
* <li>the period values are all equal to 0</li> | |||
* <li>the component is a file (production or test)</li> | |||
* <li>optimization algorithm is enabled on the metric</li> | |||
* <li>the measure computed equals the metric best value</li> | |||
* <li>the period values are all equal to 0</li> | |||
* </ul> | |||
* To recreate a best value 2 different cases: | |||
* <ul> | |||
* <li>Metric starts with 'new_' (ex: new_violations): the best value measure doesn't have a value and period values are all equal to 0</li> | |||
* <li>Other metrics: the best value measure has a value of 0 and no period value</li> | |||
* <li>Metric starts with 'new_' (ex: new_violations): the best value measure doesn't have a value and period values are all equal to 0</li> | |||
* <li>Other metrics: the best value measure has a value of 0 and no period value</li> | |||
* </ul> | |||
*/ | |||
public class ComponentTreeAction implements MeasuresWsAction { | |||
@@ -177,8 +177,8 @@ public class ComponentTreeAction implements MeasuresWsAction { | |||
public void define(WebService.NewController context) { | |||
WebService.NewAction action = context.createAction(ACTION_COMPONENT_TREE) | |||
.setDescription(format("Navigate through components based on the chosen strategy with specified measures. The %s or the %s parameter must be provided.<br>" + | |||
"Requires the following permission: 'Browse' on the specified project.<br>" + | |||
"When limiting search with the %s parameter, directories are not returned.", | |||
"Requires the following permission: 'Browse' on the specified project.<br>" + | |||
"When limiting search with the %s parameter, directories are not returned.", | |||
DEPRECATED_PARAM_BASE_COMPONENT_ID, PARAM_COMPONENT, Param.TEXT_QUERY)) | |||
.setResponseExample(getClass().getResource("component_tree-example.json")) | |||
.setSince("5.4") | |||
@@ -316,8 +316,8 @@ public class ComponentTreeAction implements MeasuresWsAction { | |||
} | |||
} | |||
if (arePeriodsInResponse(request)) { | |||
response.getPeriodsBuilder().addAllPeriods(data.getPeriods()); | |||
if (arePeriodsInResponse(request) && data.getPeriod() != null) { | |||
response.getPeriodsBuilder().addPeriods(data.getPeriod()); | |||
} | |||
return response.build(); | |||
@@ -431,7 +431,7 @@ public class ComponentTreeAction implements MeasuresWsAction { | |||
.setComponentCount(componentCount) | |||
.setMeasuresByComponentUuidAndMetric(measuresByComponentUuidAndMetric) | |||
.setMetrics(metrics) | |||
.setPeriods(snapshotToWsPeriods(baseSnapshot.get())) | |||
.setPeriod(snapshotToWsPeriods(baseSnapshot.get()).orElse(null)) | |||
.setReferenceComponentsByUuid(searchReferenceComponentsById(dbSession, components)) | |||
.build(); | |||
} |
@@ -39,7 +39,7 @@ class ComponentTreeData { | |||
private final int componentCount; | |||
private final Map<String, ComponentDto> referenceComponentsByUuid; | |||
private final List<MetricDto> metrics; | |||
private final List<Measures.Period> periods; | |||
private final Measures.Period period; | |||
private final Table<String, MetricDto, Measure> measuresByComponentUuidAndMetric; | |||
private ComponentTreeData(Builder builder) { | |||
@@ -49,7 +49,7 @@ class ComponentTreeData { | |||
this.referenceComponentsByUuid = builder.referenceComponentsByUuid; | |||
this.metrics = builder.metrics; | |||
this.measuresByComponentUuidAndMetric = builder.measuresByComponentUuidAndMetric; | |||
this.periods = builder.periods; | |||
this.period = builder.period; | |||
} | |||
public ComponentDto getBaseComponent() { | |||
@@ -77,8 +77,8 @@ class ComponentTreeData { | |||
} | |||
@CheckForNull | |||
List<Measures.Period> getPeriods() { | |||
return periods; | |||
Measures.Period getPeriod() { | |||
return period; | |||
} | |||
@CheckForNull | |||
@@ -96,7 +96,7 @@ class ComponentTreeData { | |||
private Map<String, ComponentDto> referenceComponentsByUuid; | |||
private int componentCount; | |||
private List<MetricDto> metrics; | |||
private List<Measures.Period> periods; | |||
private Measures.Period period; | |||
private Table<String, MetricDto, Measure> measuresByComponentUuidAndMetric; | |||
private Builder() { | |||
@@ -123,8 +123,8 @@ class ComponentTreeData { | |||
return this; | |||
} | |||
public Builder setPeriods(List<Measures.Period> periods) { | |||
this.periods = periods; | |||
public Builder setPeriod(@Nullable Measures.Period period) { | |||
this.period = period; | |||
return this; | |||
} | |||
@@ -19,31 +19,28 @@ | |||
*/ | |||
package org.sonar.server.measure.ws; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import javax.annotation.Nullable; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonarqube.ws.Measures; | |||
import static java.util.Collections.emptyList; | |||
import static org.sonar.api.utils.DateUtils.formatDateTime; | |||
class SnapshotDtoToWsPeriods { | |||
private SnapshotDtoToWsPeriods() { | |||
class SnapshotDtoToWsPeriod { | |||
private SnapshotDtoToWsPeriod() { | |||
// prevent instantiation | |||
} | |||
static List<Measures.Period> snapshotToWsPeriods(@Nullable SnapshotDto snapshot) { | |||
static Optional<Measures.Period> snapshotToWsPeriods(@Nullable SnapshotDto snapshot) { | |||
if (snapshot == null) { | |||
return emptyList(); | |||
return Optional.empty(); | |||
} | |||
List<Measures.Period> periods = new ArrayList<>(); | |||
if (snapshot.getPeriodDate() != null) { | |||
periods.add(snapshotDtoToWsPeriod(snapshot)); | |||
return Optional.of(snapshotDtoToWsPeriod(snapshot)); | |||
} | |||
return periods; | |||
return Optional.empty(); | |||
} | |||
private static Measures.Period snapshotDtoToWsPeriod(SnapshotDto snapshot) { |