diff options
Diffstat (limited to 'server')
9 files changed, 92 insertions, 39 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java index c604904529a..b21f8052d95 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchAction.java @@ -133,7 +133,7 @@ public class SearchAction implements ComponentsWsAction { paging.pageSize()); } - private SearchWsResponse buildResponse(List<ComponentDto> components, Paging paging) { + private static SearchWsResponse buildResponse(List<ComponentDto> components, Paging paging) { WsComponents.SearchWsResponse.Builder responseBuilder = SearchWsResponse.newBuilder(); responseBuilder.getPagingBuilder() .setPageIndex(paging.pageIndex()) diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java index 3820a4ddc05..dc5c61e1787 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java @@ -33,6 +33,7 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.api.user.User; import org.sonar.api.utils.text.JsonWriter; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.MyBatis; import org.sonar.db.component.ComponentDto; @@ -40,7 +41,6 @@ import org.sonar.db.component.SnapshotDto; import org.sonar.db.measure.custom.CustomMeasureDto; import org.sonar.db.metric.MetricDto; import org.sonar.server.component.ComponentFinder; -import org.sonar.server.db.DbClient; import org.sonar.server.es.SearchOptions; import org.sonar.server.user.UserSession; import org.sonar.server.user.index.UserIndex; diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java index b7af8e1b042..2c8b748e8ae 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java @@ -64,7 +64,7 @@ import static org.sonar.server.measure.ws.ComponentDtoToWsComponent.componentDto import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createAdditionalFieldsParameter; 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.snapshotsToPeriods; +import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriods.snapshotToWsPeriods; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.WsUtils.checkRequest; @@ -131,7 +131,7 @@ public class ComponentAction implements MeasuresWsAction { checkPermissions(component); SnapshotDto lastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentId(dbSession, component.getId()); List<MetricDto> metrics = searchMetrics(dbSession, request); - List<WsMeasures.Period> periods = snapshotsToPeriods(lastSnapshot); + List<WsMeasures.Period> periods = snapshotToWsPeriods(lastSnapshot); List<MeasureDto> measures = searchMeasures(dbSession, component, lastSnapshot, metrics, periods); return buildResponse(request, component, refComponent, measures, metrics, periods); diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java index 3bb6254614a..42f695add9b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java @@ -65,13 +65,13 @@ import static com.google.common.collect.Sets.newHashSet; import static java.lang.String.format; import static java.util.Collections.emptyMap; import static java.util.Collections.singletonList; -import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.server.component.ComponentFinder.ParamNames.BASE_COMPONENT_ID_AND_KEY; import static org.sonar.server.measure.ws.ComponentTreeAction.ALL_STRATEGY; import static org.sonar.server.measure.ws.ComponentTreeAction.CHILDREN_STRATEGY; import static org.sonar.server.measure.ws.ComponentTreeAction.LEAVES_STRATEGY; import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_SORT; import static org.sonar.server.measure.ws.ComponentTreeAction.NAME_SORT; +import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriods.snapshotToWsPeriods; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; public class ComponentTreeDataLoader { @@ -106,7 +106,7 @@ public class ComponentTreeDataLoader { List<ComponentDtoWithSnapshotId> components = componentDtosAndTotal.componentDtos; int componentCount = componentDtosAndTotal.total; List<MetricDto> metrics = searchMetrics(dbSession, wsRequest); - List<WsMeasures.Period> periods = periodsFromSnapshot(baseSnapshot); + List<WsMeasures.Period> periods = snapshotToWsPeriods(baseSnapshot); Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric = searchMeasuresByComponentUuidAndMetric(dbSession, baseComponent, baseSnapshot, components, metrics, periods); @@ -230,33 +230,6 @@ public class ComponentTreeDataLoader { } } - private static List<WsMeasures.Period> periodsFromSnapshot(SnapshotDto baseSnapshot) { - List<WsMeasures.Period> periods = new ArrayList<>(); - for (int periodIndex = 1; periodIndex <= 5; periodIndex++) { - if (baseSnapshot.getPeriodDate(periodIndex) != null) { - periods.add(snapshotDtoToWsPeriod(baseSnapshot, periodIndex)); - } - } - - return periods; - } - - private static WsMeasures.Period snapshotDtoToWsPeriod(SnapshotDto snapshot, int periodIndex) { - WsMeasures.Period.Builder period = WsMeasures.Period.newBuilder(); - period.setIndex(periodIndex); - if (snapshot.getPeriodMode(periodIndex) != null) { - period.setMode(snapshot.getPeriodMode(periodIndex)); - } - if (snapshot.getPeriodModeParameter(periodIndex) != null) { - period.setParameter(snapshot.getPeriodModeParameter(periodIndex)); - } - if (snapshot.getPeriodDate(periodIndex) != null) { - period.setDate(formatDateTime(snapshot.getPeriodDate(periodIndex))); - } - - return period.build(); - } - private static List<ComponentDtoWithSnapshotId> sortComponents(List<ComponentDtoWithSnapshotId> components, ComponentTreeWsRequest wsRequest, List<MetricDto> metrics, Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric) { if (!wsRequest.getSort().contains(METRIC_SORT)) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java index 50b7c1a0292..b99ec27a3b3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java @@ -101,7 +101,7 @@ class ComponentTreeSort { */ private static Ordering<ComponentDtoWithSnapshotId> metricOrdering(ComponentTreeWsRequest wsRequest, List<MetricDto> metrics, Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric) { - if (wsRequest.getMetricSort()==null) { + if (wsRequest.getMetricSort() == null) { return componentNameOrdering(wsRequest.getAsc()); } Map<String, MetricDto> metricsByKey = Maps.uniqueIndex(metrics, MetricDtoFunctions.toKey()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SnapshotDtoToWsPeriods.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SnapshotDtoToWsPeriods.java index 8418f3a4f96..1f3864175c0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SnapshotDtoToWsPeriods.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SnapshotDtoToWsPeriods.java @@ -33,7 +33,7 @@ class SnapshotDtoToWsPeriods { // prevent instantiation } - static List<WsMeasures.Period> snapshotsToPeriods(@Nullable SnapshotDto snapshot) { + static List<WsMeasures.Period> snapshotToWsPeriods(@Nullable SnapshotDto snapshot) { if (snapshot == null) { return emptyList(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/DomainsAction.java b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/DomainsAction.java index c90585e25a3..7ecd84e7b29 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/DomainsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/DomainsAction.java @@ -19,15 +19,14 @@ */ package org.sonar.server.metric.ws; +import java.util.List; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.text.JsonWriter; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.MyBatis; -import org.sonar.server.db.DbClient; - -import java.util.List; public class DomainsAction implements MetricsWsAction { diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionUpdater.java index 6583bcda716..a9cd97db6a3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionUpdater.java @@ -177,7 +177,7 @@ public class PermissionUpdater { } } - private boolean shouldSkipPermissionChange(Operation operation, List<String> existingPermissions, PermissionChange permissionChange) { + private static boolean shouldSkipPermissionChange(Operation operation, List<String> existingPermissions, PermissionChange permissionChange) { return (Operation.ADD == operation && existingPermissions.contains(permissionChange.permission())) || (Operation.REMOVE == operation && !existingPermissions.contains(permissionChange.permission())); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowDataTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowDataTest.java new file mode 100644 index 00000000000..3de3853872e --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowDataTest.java @@ -0,0 +1,81 @@ +/* + * 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.sonar.server.component.ws; + +import java.util.Collections; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.SnapshotDto; + +import static com.google.common.collect.Lists.newArrayList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.db.component.ComponentTesting.newProjectDto; +import static org.sonar.db.component.SnapshotTesting.newSnapshotForProject; + +public class ShowDataTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + ComponentDto project = newProjectDto().setId(42L); + + ShowData underTest; + + @Test + public void no_ancestors() { + underTest = ShowData.builder( + newSnapshotForProject(project).setPath(null)) + .withAncestorsSnapshots(Collections.<SnapshotDto>emptyList()) + .andAncestorComponents(Collections.<ComponentDto>emptyList()); + + assertThat(underTest.getComponents()).isEmpty(); + } + + @Test + public void fail_when_inconsistent_snapshot_ancestors_data() { + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Missing ancestor"); + + underTest = ShowData.builder( + newSnapshotForProject(project).setPath("1.2.3.")) + .withAncestorsSnapshots(newArrayList( + newSnapshotForProject(project).setId(1L), + newSnapshotForProject(project).setId(2L))) + // missing snapshot with id = 3 + .andAncestorComponents(Collections.<ComponentDto>emptyList()); + } + + @Test + public void fail_when_inconsistent_component_ancestors_data() { + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Missing ancestor"); + + underTest = ShowData.builder( + newSnapshotForProject(project).setPath("1.2.3.")) + .withAncestorsSnapshots(newArrayList( + newSnapshotForProject(project).setId(1L), + newSnapshotForProject(project).setId(2L), + newSnapshotForProject(project).setId(3L))) + .andAncestorComponents(Collections.<ComponentDto>emptyList()); + } +} |