+++ /dev/null
-/*
- * 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.measure.template;
-
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.web.Filter;
-import org.sonar.api.web.FilterColumn;
-import org.sonar.api.web.FilterTemplate;
-
-/**
- * Default filter for looking for user favourite resources.
- *
- * @since 3.1
- */
-public class MyFavouritesFilter extends FilterTemplate {
- public static final String NAME = "My favourites";
-
- @Override
- public String getName() {
- return NAME;
- }
-
- @Override
- public Filter createFilter() {
- return Filter.create()
- .setDisplayAs(Filter.LIST)
- .setFavouritesOnly(true)
- .add(FilterColumn.create("metric", CoreMetrics.ALERT_STATUS_KEY, FilterColumn.DESC, false))
- .add(FilterColumn.create("name", null, FilterColumn.ASC, false))
- .add(FilterColumn.create("date", null, FilterColumn.DESC, false));
- }
-}
+++ /dev/null
-/*
- * 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.measure.template;
-
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.web.Criterion;
-import org.sonar.api.web.Filter;
-import org.sonar.api.web.FilterColumn;
-import org.sonar.api.web.FilterTemplate;
-
-/**
- * Default projects filter.
- *
- * @since 3.1
- */
-public class ProjectFilter extends FilterTemplate {
- public static final String NAME = "Projects";
-
- @Override
- public String getName() {
- return NAME;
- }
-
- @Override
- public Filter createFilter() {
- return Filter.create()
- .setDisplayAs(Filter.LIST)
- .add(Criterion.createForQualifier(Qualifiers.PROJECT))
- .add(FilterColumn.create("metric", CoreMetrics.ALERT_STATUS_KEY, FilterColumn.DESC, false))
- .add(FilterColumn.create("name", null, FilterColumn.ASC, false))
- .add(FilterColumn.create("version", null, FilterColumn.DESC, false))
- .add(FilterColumn.create("metric", CoreMetrics.NCLOC_KEY, FilterColumn.DESC, false))
- .add(FilterColumn.create("metric", CoreMetrics.BUGS_KEY, FilterColumn.DESC, false))
- .add(FilterColumn.create("metric", CoreMetrics.VULNERABILITIES_KEY, FilterColumn.DESC, false))
- .add(FilterColumn.create("metric", CoreMetrics.CODE_SMELLS_KEY, FilterColumn.DESC, false))
- .add(FilterColumn.create("date", null, FilterColumn.DESC, false));
- }
-}
+++ /dev/null
-/*
- * 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.
- */
-@javax.annotation.ParametersAreNonnullByDefault
-package org.sonar.server.measure.template;
import org.sonar.server.license.ws.LicensesWsModule;
import org.sonar.server.measure.custom.ws.CustomMeasuresWsModule;
import org.sonar.server.measure.index.ProjectsEsModule;
-import org.sonar.server.measure.template.MyFavouritesFilter;
-import org.sonar.server.measure.template.ProjectFilter;
import org.sonar.server.measure.ws.MeasuresWsModule;
import org.sonar.server.measure.ws.TimeMachineWs;
import org.sonar.server.metric.CoreCustomMetrics;
MetricsWsModule.class,
MeasuresWsModule.class,
CustomMeasuresWsModule.class,
- ProjectFilter.class,
- MyFavouritesFilter.class,
CoreCustomMetrics.class,
DefaultMetricFinder.class,
TimeMachineWs.class,
+++ /dev/null
-/*
- * 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.measure.template;
-
-import org.junit.Test;
-import org.sonar.api.web.Filter;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class MyFavouritesFilterTest {
- @Test
- public void should_create_filter() {
- MyFavouritesFilter template = new MyFavouritesFilter();
-
- Filter filter = template.createFilter();
-
- assertThat(template.getName()).isEqualTo("My favourites");
- assertThat(filter).isNotNull();
- assertThat(filter.isFavouritesOnly()).isTrue();
- assertThat(filter.getCriteria()).isEmpty();
- assertThat(filter.getColumns()).hasSize(3);
- }
-}
+++ /dev/null
-/*
- * 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.measure.template;
-
-import org.junit.Test;
-import org.sonar.api.web.Filter;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class ProjectFilterTest {
- @Test
- public void should_create_filter() {
- ProjectFilter template = new ProjectFilter();
-
- Filter filter = template.createFilter();
-
- assertThat(template.getName()).isEqualTo("Projects");
- assertThat(filter).isNotNull();
- assertThat(filter.getCriteria()).hasSize(1);
- assertThat(filter.getColumns()).hasSize(8);
- }
-}
+++ /dev/null
-/*
- * 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.api.web;
-
-import com.google.common.base.Preconditions;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Definition of a filter.
- *
- * <p>Its name can be retrieved using the i18n mechanism, using the keys "filter.<id>.name".
- *
- * @since 3.1
- */
-public final class Filter {
- public static final String LIST = "list";
- public static final String TREEMAP = "treemap";
-
- private boolean favouritesOnly;
- private String displayAs;
- private int pageSize;
- private List<Criterion> criteria;
- private List<FilterColumn> columns;
-
- private Filter() {
- displayAs = LIST;
- criteria = new ArrayList<>();
- columns = new ArrayList<>();
- }
-
- /**
- * Creates a new {@link Filter}.
- */
- public static Filter create() {
- return new Filter();
- }
-
- /**
- * Get the list of {@link Criterion} used to narrow down the results of this {@link Filter}.
- *
- * @return the criteria
- */
- public List<Criterion> getCriteria() {
- return criteria;
- }
-
- /**
- * Add a {@link Criterion} to the list used to narrow down the results of this {@link Filter}.
- *
- * @return this filter
- */
- public Filter add(Criterion criterion) {
- this.criteria.add(criterion);
- return this;
- }
-
- /**
- * Get the list of {@link FilterColumn} displayed by this {@link Filter}.
- *
- * @return this columns
- */
- public List<FilterColumn> getColumns() {
- return columns;
- }
-
- /**
- * Add a {@link FilterColumn} to the list of columns displayed by this {@link Filter}.
- *
- * @return this filter
- */
- public Filter add(FilterColumn column) {
- this.columns.add(column);
- return this;
- }
-
- /**
- * The {@link Filter} can be configured to return only favourites.
- *
- * @return <code>true</code> if favourites only are returned
- */
- public boolean isFavouritesOnly() {
- return favouritesOnly;
- }
-
- /**
- * The {@link Filter} can be configured to return only favourites.
- */
- public Filter setFavouritesOnly(boolean favouritesOnly) {
- this.favouritesOnly = favouritesOnly;
- return this;
- }
-
- /**
- * Get the type of display used by this {@link Filter}.
- *
- * <p>Can be either {@code #LIST} or {@code #TREEMAP}
- *
- * @return the display type
- */
- public String getDisplayAs() {
- return displayAs;
- }
-
- /**
- * Set the type of display used by this {@link Filter}.
- *
- * <p>Can be either {@code #LIST} or {@code #TREEMAP}
- *
- * @return this filter
- * @throws IllegalArgumentException if {@code displayAs} is not {@code #LIST} or {@code #TREEMAP}
- */
- public Filter setDisplayAs(String displayAs) {
- Preconditions.checkArgument(LIST.equals(displayAs) || TREEMAP.equals(displayAs), "Default display should be either %s or %s, not %s", LIST, TREEMAP, displayAs);
- this.displayAs = displayAs;
- return this;
- }
-
- /**
- * Get the size of a page displayed this {@link Filter}.
- *
- * <p>The page size is between <code>20</code> and <code>200</code> (included)
- *
- * @return the display type
- */
- public int getPageSize() {
- return pageSize;
- }
-
- /**
- * Set the size of a page displayed this {@link Filter}.
- *
- * <p>The page size should be between <code>20</code> and <code>200</code> (included)
- *
- * @return the display type
- * @throws IllegalArgumentException if {@code pageSize} is not lower than {@code 20} or greater than {@code 200}
- */
- public Filter setPageSize(int pageSize) {
- Preconditions.checkArgument((pageSize >= 20) && (pageSize <= 200), "page size should be between 20 and 200");
- this.pageSize = pageSize;
- return this;
- }
-}
+++ /dev/null
-/*
- * 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.api.web;
-
-import com.google.common.collect.ImmutableSortedSet;
-
-import java.util.Set;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Definition of a {@link Filter} column.
- *
- * @since 3.1
- */
-public final class FilterColumn {
- public static final String ASC = "ASC";
- public static final String DESC = "DESC";
- public static final Set<String> DIRECTIONS = ImmutableSortedSet.of(ASC, DESC);
-
- private final String family;
- private final String key;
- private final String sortDirection;
- private final boolean variation;
-
- private FilterColumn(String family, String key, String sortDirection, boolean variation) {
- Preconditions.checkArgument(DIRECTIONS.contains(sortDirection), "Valid directions are %s, not '%s'", DIRECTIONS, sortDirection);
-
- this.family = family;
- this.key = key;
- this.sortDirection = sortDirection;
- this.variation = variation;
- }
-
- /**
- * Creates a new {@link FilterColumn}.
- *
- * <p>Valid values for the {@code sortDirection} are {@code #ASC}, {@code #DESC}
- *
- * <p>When the @{see Filter} is persisted, a validation is made on the {@code family} and the {@code key}.
- * They should point to a valid column description.
- *
- * @throws IllegalArgumentException if {@code sortDirection} is not valid
- */
- public static FilterColumn create(String family, String key, String sortDirection, boolean variation) {
- return new FilterColumn(family, key, sortDirection, variation);
- }
-
- /**
- * Get the the column's family.
- *
- * @return the family
- */
- public String getFamily() {
- return family;
- }
-
- /**
- * Get the the column's key.
- *
- * @return the key
- */
- public String getKey() {
- return key;
- }
-
- /**
- * Get the the column's sort direction.
- *
- * @return the sort direction
- */
- public String getSortDirection() {
- return sortDirection;
- }
-
- /**
- * A column can be based on the variation of a value rather than on the value itself.
- *
- * @return <code>true</code> when the variation is used rather than the value
- */
- public boolean isVariation() {
- return variation;
- }
-}
+++ /dev/null
-/*
- * 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.api.web;
-
-import org.sonar.api.ExtensionPoint;
-import org.sonar.api.server.ServerSide;
-
-/**
- * This extension point must be implemented to define a new filter.
- *
- * @since 3.1
- */
-@ServerSide
-@ExtensionPoint
-public abstract class FilterTemplate {
-
- /**
- * Returns the {@link Filter} object that represents the filter to use.
- *
- * @return the filter
- */
- public abstract Filter createFilter();
-
- /**
- * Filter name
- */
- public abstract String getName();
-}
+++ /dev/null
-/*
- * 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.api.web;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-public class FilterColumnTest {
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
- @Test
- public void should_accept_valid_direction() {
- FilterColumn.create("", "", "ASC", false);
- FilterColumn.create("", "", "DESC", false);
- }
-
- @Test
- public void should_fail_on_invalid_direction() {
- exception.expect(IllegalArgumentException.class);
- exception.expectMessage("Valid directions are [ASC, DESC], not 'UNKNOWN'");
-
- FilterColumn.create("", "", "UNKNOWN", false);
- }
-
-}
+++ /dev/null
-/*
- * 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.api.web;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class FilterTest {
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
- @Test
- public void should_create_filter() {
- Filter filter = Filter.create()
- .setDisplayAs("list")
- .setFavouritesOnly(true)
- .setPageSize(100);
-
- assertThat(filter.getDisplayAs()).isEqualTo("list");
- assertThat(filter.isFavouritesOnly()).isTrue();
- assertThat(filter.getPageSize()).isEqualTo(100);
- }
-
- @Test
- public void should_add_criteria() {
- Criterion criterion1 = Criterion.createForQualifier("A");
- Criterion criterion2 = Criterion.createForQualifier("A");
- Filter filter = Filter.create()
- .add(criterion1)
- .add(criterion2);
-
- assertThat(filter.getCriteria()).containsExactly(criterion1, criterion2);
- }
-
- @Test
- public void should_add_columns() {
- FilterColumn column1 = FilterColumn.create("", "", "ASC", false);
- FilterColumn column2 = FilterColumn.create("", "", "DESC", false);
- Filter filter = Filter.create()
- .add(column1)
- .add(column2);
-
- assertThat(filter.getColumns()).containsExactly(column1, column2);
- }
-
- @Test
- public void should_accept_valid_periods() {
- Filter.create().setDisplayAs("list");
- Filter.create().setDisplayAs("treemap");
- }
-
- @Test
- public void should_fail_on_invalid_display() {
- exception.expect(IllegalArgumentException.class);
- exception.expectMessage("Default display should be either list or treemap, not <invalid>");
-
- Filter.create().setDisplayAs("<invalid>");
- }
-
- @Test
- public void should_accept_valid_pageSize() {
- Filter.create().setPageSize(20);
- Filter.create().setPageSize(200);
- }
-
- @Test
- public void should_fail_on_pageSize_too_small() {
- exception.expect(IllegalArgumentException.class);
- exception.expectMessage("page size should be between 20 and 200");
-
- Filter.create().setPageSize(19);
- }
-
- @Test
- public void should_fail_on_pageSize_too_high() {
- exception.expect(IllegalArgumentException.class);
- exception.expectMessage("page size should be between 20 and 200");
-
- Filter.create().setPageSize(201);
- }
-}