import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.batch.protocol.input.GlobalRepositories;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
import org.sonar.server.db.DbClient;
import org.sonar.batch.protocol.output.BatchReport.Range;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.core.measure.db.MeasureDto;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
import org.sonar.server.computation.ComputationContext;
import org.sonar.server.event.db.EventDao;
import org.sonar.server.issue.db.IssueDao;
import org.sonar.server.measure.persistence.MeasureDao;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
import org.sonar.server.qualityprofile.db.ActiveRuleDao;
import org.sonar.server.rule.db.RuleDao;
import org.sonar.server.source.db.FileSourceDao;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.persistence;
-
-import com.google.common.collect.Maps;
-import org.apache.ibatis.session.RowBounds;
-import org.sonar.api.server.ServerSide;
-import org.sonar.core.measure.db.MetricDto;
-import org.sonar.core.measure.db.MetricMapper;
-import org.sonar.core.persistence.DaoComponent;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.server.es.SearchOptions;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.List;
-import java.util.Map;
-
-@ServerSide
-public class MetricDao implements DaoComponent {
-
- @CheckForNull
- public MetricDto selectByKey(DbSession session, String key) {
- return session.getMapper(MetricMapper.class).selectByKey(key);
- }
-
- public List<MetricDto> selectEnabled(DbSession session) {
- return session.getMapper(MetricMapper.class).selectAllEnabled();
- }
-
- public List<MetricDto> selectEnabled(DbSession session, @Nullable Boolean isCustom, SearchOptions searchOptions) {
- Map<String, Object> properties = Maps.newHashMapWithExpectedSize(1);
- if (isCustom != null) {
- properties.put("isCustom", isCustom);
- }
-
- return session.getMapper(MetricMapper.class).selectAllEnabled(properties, new RowBounds(searchOptions.getOffset(), searchOptions.getLimit()));
- }
-
- public void insert(DbSession session, MetricDto dto) {
- session.getMapper(MetricMapper.class).insert(dto);
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.ws;
-
-import org.sonar.api.measures.Metric;
-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.server.ws.WebService.Param;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.core.measure.db.MetricDto;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.es.SearchOptions;
-
-import javax.annotation.Nullable;
-
-import java.util.List;
-import java.util.Set;
-
-import static com.google.common.collect.Sets.newHashSet;
-
-public class ListAction implements MetricsWsAction {
-
- public static final String PARAM_IS_CUSTOM = "is_custom";
-
- public static final String FIELD_ID = "id";
- public static final String FIELD_KEY = "key";
- public static final String FIELD_NAME = "name";
- public static final String FIELD_DESCRIPTION = "description";
- public static final String FIELD_DOMAIN = "domain";
- public static final String FIELD_TYPE = "type";
- private static final Set<String> POSSIBLE_FIELDS = newHashSet(FIELD_ID, FIELD_KEY, FIELD_NAME, FIELD_DESCRIPTION, FIELD_DOMAIN, FIELD_TYPE);
-
- private final DbClient dbClient;
-
- public ListAction(DbClient dbClient) {
- this.dbClient = dbClient;
- }
-
- @Override
- public void define(WebService.NewController context) {
- WebService.NewAction action = context.createAction("list")
- .setSince("5.2")
- .setResponseExample(getClass().getResource("example-list.json"))
- .addPagingParams(100)
- .addFieldsParam(POSSIBLE_FIELDS)
- .setHandler(this);
-
- action.createParam(PARAM_IS_CUSTOM)
- .setExampleValue("true")
- .setDescription("Choose custom metrics following 3 cases:" +
- "<ul>" +
- "<li>true: only custom metrics are returned</li>" +
- "<li>false: only non custom metrics are returned</li>" +
- "<li>not specified: all metrics are returned</li>" +
- "</ul>");
- }
-
- @Override
- public void handle(Request request, Response response) throws Exception {
- SearchOptions searchOptions = new SearchOptions()
- .setPage(request.mandatoryParamAsInt(Param.PAGE),
- request.mandatoryParamAsInt(Param.PAGE_SIZE));
- Boolean isCustom = request.paramAsBoolean(PARAM_IS_CUSTOM);
- DbSession dbSession = dbClient.openSession(false);
- try {
- List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions);
- JsonWriter json = response.newJsonWriter();
- json.beginObject();
- Set<String> desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS));
- writeMetrics(json, metrics, desiredFields);
- json.endObject();
- json.close();
- } finally {
- MyBatis.closeQuietly(dbSession);
- }
- }
-
- private Set<String> desiredFields(@Nullable List<String> fields) {
- if (fields == null || fields.isEmpty()) {
- return POSSIBLE_FIELDS;
- }
-
- return newHashSet(fields);
- }
-
- private void writeMetrics(JsonWriter json, List<MetricDto> metrics, Set<String> desiredFields) {
- json.name("metrics");
- json.beginArray();
- for (MetricDto metric : metrics) {
- json.beginObject();
- json.prop(FIELD_ID, String.valueOf(metric.getId()));
- json.prop(FIELD_KEY, metric.getKey());
- writeIfDesired(json, FIELD_NAME, metric.getShortName(), desiredFields);
- writeIfDesired(json, FIELD_DESCRIPTION, metric.getDescription(), desiredFields);
- writeIfDesired(json, FIELD_DOMAIN, metric.getDomain(), desiredFields);
- writeIfDesired(json, FIELD_TYPE, Metric.ValueType.descriptionOf(metric.getValueType()), desiredFields);
- json.endObject();
- }
- json.endArray();
- }
-
- private void writeIfDesired(JsonWriter json, String field, String value, Set<String> desiredFields) {
- if (desiredFields.contains(field)) {
- json.prop(field, value);
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.ws;
-
-import org.sonar.api.server.ws.RailsHandler;
-import org.sonar.api.server.ws.WebService;
-
-public class MetricsWs implements WebService {
-
- private final MetricsWsAction[] actions;
-
- public MetricsWs(MetricsWsAction... actions) {
- this.actions = actions;
- }
-
- @Override
- public void define(Context context) {
- NewController controller = context.createController("api/metrics");
- controller.setDescription("Metrics management");
- controller.setSince("2.6");
-
- for (MetricsWsAction action : actions) {
- action.define(controller);
- }
- defineIndexAction(controller);
-
- controller.done();
- }
-
- private void defineIndexAction(NewController controller) {
- controller.createAction("index")
- .setDescription("Documentation of this web service is available <a href=\"http://redirect.sonarsource.com/doc/old-web-service-api.html\">here</a>")
- .setSince("2.6")
- .setHandler(RailsHandler.INSTANCE);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.ws;
-
-import org.sonar.server.ws.WsAction;
-
-public interface MetricsWsAction extends WsAction {
- // marker interface
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.metric.persistence;
+
+import com.google.common.collect.Maps;
+import org.apache.ibatis.session.RowBounds;
+import org.sonar.api.server.ServerSide;
+import org.sonar.core.metric.db.MetricDto;
+import org.sonar.core.metric.db.MetricMapper;
+import org.sonar.core.persistence.DaoComponent;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.server.es.SearchOptions;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import java.util.List;
+import java.util.Map;
+
+@ServerSide
+public class MetricDao implements DaoComponent {
+
+ @CheckForNull
+ public MetricDto selectByKey(DbSession session, String key) {
+ return session.getMapper(MetricMapper.class).selectByKey(key);
+ }
+
+ public List<MetricDto> selectEnabled(DbSession session) {
+ return session.getMapper(MetricMapper.class).selectAllEnabled();
+ }
+
+ public List<MetricDto> selectEnabled(DbSession session, @Nullable Boolean isCustom, SearchOptions searchOptions) {
+ Map<String, Object> properties = Maps.newHashMapWithExpectedSize(1);
+ if (isCustom != null) {
+ properties.put("isCustom", isCustom);
+ }
+
+ return session.getMapper(MetricMapper.class).selectAllEnabled(properties, new RowBounds(searchOptions.getOffset(), searchOptions.getLimit()));
+ }
+
+ public void insert(DbSession session, MetricDto dto) {
+ session.getMapper(MetricMapper.class).insert(dto);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.server.metric.persistence;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.metric.ws;
+
+import org.sonar.api.measures.Metric;
+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.server.ws.WebService.Param;
+import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.core.metric.db.MetricDto;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.MyBatis;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.es.SearchOptions;
+
+import javax.annotation.Nullable;
+
+import java.util.List;
+import java.util.Set;
+
+import static com.google.common.collect.Sets.newHashSet;
+
+public class ListAction implements MetricsWsAction {
+
+ public static final String PARAM_IS_CUSTOM = "is_custom";
+
+ public static final String FIELD_ID = "id";
+ public static final String FIELD_KEY = "key";
+ public static final String FIELD_NAME = "name";
+ public static final String FIELD_DESCRIPTION = "description";
+ public static final String FIELD_DOMAIN = "domain";
+ public static final String FIELD_TYPE = "type";
+ private static final Set<String> POSSIBLE_FIELDS = newHashSet(FIELD_ID, FIELD_KEY, FIELD_NAME, FIELD_DESCRIPTION, FIELD_DOMAIN, FIELD_TYPE);
+
+ private final DbClient dbClient;
+
+ public ListAction(DbClient dbClient) {
+ this.dbClient = dbClient;
+ }
+
+ @Override
+ public void define(WebService.NewController context) {
+ WebService.NewAction action = context.createAction("list")
+ .setSince("5.2")
+ .setResponseExample(getClass().getResource("example-list.json"))
+ .addPagingParams(100)
+ .addFieldsParam(POSSIBLE_FIELDS)
+ .setHandler(this);
+
+ action.createParam(PARAM_IS_CUSTOM)
+ .setExampleValue("true")
+ .setDescription("Choose custom metrics following 3 cases:" +
+ "<ul>" +
+ "<li>true: only custom metrics are returned</li>" +
+ "<li>false: only non custom metrics are returned</li>" +
+ "<li>not specified: all metrics are returned</li>" +
+ "</ul>");
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ SearchOptions searchOptions = new SearchOptions()
+ .setPage(request.mandatoryParamAsInt(Param.PAGE),
+ request.mandatoryParamAsInt(Param.PAGE_SIZE));
+ Boolean isCustom = request.paramAsBoolean(PARAM_IS_CUSTOM);
+ DbSession dbSession = dbClient.openSession(false);
+ try {
+ List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions);
+ JsonWriter json = response.newJsonWriter();
+ json.beginObject();
+ Set<String> desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS));
+ writeMetrics(json, metrics, desiredFields);
+ json.endObject();
+ json.close();
+ } finally {
+ MyBatis.closeQuietly(dbSession);
+ }
+ }
+
+ private Set<String> desiredFields(@Nullable List<String> fields) {
+ if (fields == null || fields.isEmpty()) {
+ return POSSIBLE_FIELDS;
+ }
+
+ return newHashSet(fields);
+ }
+
+ private void writeMetrics(JsonWriter json, List<MetricDto> metrics, Set<String> desiredFields) {
+ json.name("metrics");
+ json.beginArray();
+ for (MetricDto metric : metrics) {
+ json.beginObject();
+ json.prop(FIELD_ID, String.valueOf(metric.getId()));
+ json.prop(FIELD_KEY, metric.getKey());
+ writeIfDesired(json, FIELD_NAME, metric.getShortName(), desiredFields);
+ writeIfDesired(json, FIELD_DESCRIPTION, metric.getDescription(), desiredFields);
+ writeIfDesired(json, FIELD_DOMAIN, metric.getDomain(), desiredFields);
+ writeIfDesired(json, FIELD_TYPE, Metric.ValueType.descriptionOf(metric.getValueType()), desiredFields);
+ json.endObject();
+ }
+ json.endArray();
+ }
+
+ private void writeIfDesired(JsonWriter json, String field, String value, Set<String> desiredFields) {
+ if (desiredFields.contains(field)) {
+ json.prop(field, value);
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.metric.ws;
+
+import org.sonar.api.server.ws.RailsHandler;
+import org.sonar.api.server.ws.WebService;
+
+public class MetricsWs implements WebService {
+
+ private final MetricsWsAction[] actions;
+
+ public MetricsWs(MetricsWsAction... actions) {
+ this.actions = actions;
+ }
+
+ @Override
+ public void define(Context context) {
+ NewController controller = context.createController("api/metrics");
+ controller.setDescription("Metrics management");
+ controller.setSince("2.6");
+
+ for (MetricsWsAction action : actions) {
+ action.define(controller);
+ }
+ defineIndexAction(controller);
+
+ controller.done();
+ }
+
+ private void defineIndexAction(NewController controller) {
+ controller.createAction("index")
+ .setDescription("Documentation of this web service is available <a href=\"http://redirect.sonarsource.com/doc/old-web-service-api.html\">here</a>")
+ .setSince("2.6")
+ .setHandler(RailsHandler.INSTANCE);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.metric.ws;
+
+import org.sonar.server.ws.WsAction;
+
+public interface MetricsWsAction extends WsAction {
+ // marker interface
+}
import org.sonar.server.issue.db.IssueDao;
import org.sonar.server.issue.index.IssueIndex;
import org.sonar.server.measure.persistence.MeasureDao;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
import org.sonar.server.platform.DatabaseServerCompatibility;
import org.sonar.server.platform.DefaultServerFileSystem;
import org.sonar.server.platform.Platform;
import org.sonar.server.measure.MeasureFilterExecutor;
import org.sonar.server.measure.MeasureFilterFactory;
import org.sonar.server.measure.ws.ManualMeasuresWs;
-import org.sonar.server.measure.ws.MetricsWs;
import org.sonar.server.measure.ws.TimeMachineWs;
+import org.sonar.server.metric.ws.MetricsWs;
import org.sonar.server.notifications.NotificationCenter;
import org.sonar.server.notifications.NotificationService;
import org.sonar.server.permission.InternalPermissionService;
TimeMachineWs.class,
ManualMeasuresWs.class,
MetricsWs.class,
- org.sonar.server.measure.ws.ListAction.class,
+ org.sonar.server.metric.ws.ListAction.class,
// quality gates
QualityGateDao.class,
+++ /dev/null
-{
- "metrics": [
- {
- "id": "23",
- "key": "team_size",
- "name": "Team size",
- "description": "Number of people in the team",
- "domain": "Management",
- "type": "INT"
- },
- {
- "id": "2",
- "key": "uncovered_lines",
- "name": "Uncovered lines",
- "description": "Uncovered lines",
- "domain": "Tests",
- "type": "INT"
- }
- ],
- "total": 2,
- "p": 1,
- "ps": 100
-}
--- /dev/null
+{
+ "metrics": [
+ {
+ "id": "23",
+ "key": "team_size",
+ "name": "Team size",
+ "description": "Number of people in the team",
+ "domain": "Management",
+ "type": "INT"
+ },
+ {
+ "id": "2",
+ "key": "uncovered_lines",
+ "name": "Uncovered lines",
+ "description": "Uncovered lines",
+ "domain": "Tests",
+ "type": "INT"
+ }
+ ],
+ "total": 2,
+ "p": 1,
+ "ps": 100
+}
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.properties.PropertiesDao;
import org.sonar.core.properties.PropertyDto;
import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
import static org.assertj.core.api.Assertions.assertThat;
import org.sonar.batch.protocol.output.BatchReport.Range;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.computation.ComputationContext;
import org.sonar.server.computation.component.DbComponentsRefCache.DbComponent;
import org.sonar.server.db.DbClient;
import org.sonar.server.measure.persistence.MeasureDao;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
import org.sonar.test.DbTests;
import java.io.File;
package org.sonar.server.computation.step;
-import java.io.File;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.measure.db.MeasureDto;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.DbTester;
import org.sonar.core.rule.RuleDto;
import org.sonar.server.computation.measure.MetricCache;
import org.sonar.server.db.DbClient;
import org.sonar.server.measure.persistence.MeasureDao;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
import org.sonar.server.rule.RuleTesting;
import org.sonar.server.rule.db.RuleDao;
import org.sonar.test.DbTests;
+import java.io.File;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.computation.ComputationContext;
import org.sonar.server.computation.component.DbComponentsRefCache;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.persistence;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.core.measure.db.MetricDto;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.DbTester;
-import org.sonar.test.DbTests;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class MetricDaoTest {
-
- @ClassRule
- public static DbTester dbTester = new DbTester();
-
- DbSession session;
-
- MetricDao dao;
-
- @Before
- public void createDao() {
- dbTester.truncateTables();
- session = dbTester.myBatis().openSession(false);
- dao = new MetricDao();
- }
-
- @After
- public void tearDown() {
- session.close();
- }
-
- @Test
- public void get_by_key() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- MetricDto result = dao.selectByKey(session, "coverage");
- assertThat(result.getId()).isEqualTo(2);
- assertThat(result.getKey()).isEqualTo("coverage");
- assertThat(result.getShortName()).isEqualTo("Coverage");
- assertThat(result.getDescription()).isEqualTo("Coverage by unit tests");
- assertThat(result.getDomain()).isEqualTo("Tests");
- assertThat(result.getValueType()).isEqualTo("PERCENT");
- assertThat(result.getOrigin()).isEqualTo("JAV");
- assertThat(result.getDirection()).isEqualTo(1);
- assertThat(result.isQualitative()).isTrue();
- assertThat(result.isUserManaged()).isFalse();
- assertThat(result.getWorstValue()).isEqualTo(0d);
- assertThat(result.getBestValue()).isEqualTo(100d);
- assertThat(result.isOptimizedBestValue()).isFalse();
- assertThat(result.isDeleteHistoricalData()).isFalse();
- assertThat(result.isHidden()).isFalse();
- assertThat(result.isEnabled()).isTrue();
-
- // Disabled metrics are returned
- result = dao.selectByKey(session, "disabled");
- assertThat(result.getId()).isEqualTo(3);
- assertThat(result.isEnabled()).isFalse();
- }
-
- @Test
- public void get_manual_metric() {
- dbTester.prepareDbUnit(getClass(), "manual_metric.xml");
-
- MetricDto result = dao.selectByKey(session, "manual");
- assertThat(result.getId()).isEqualTo(1);
- assertThat(result.getKey()).isEqualTo("manual");
- assertThat(result.getShortName()).isEqualTo("Manual metric");
- assertThat(result.getDescription()).isEqualTo("Manual metric");
- assertThat(result.getDomain()).isNullOrEmpty();
- assertThat(result.getValueType()).isEqualTo("INT");
- assertThat(result.getOrigin()).isEqualTo("GUI");
- assertThat(result.getDirection()).isEqualTo(0);
- assertThat(result.isQualitative()).isFalse();
- assertThat(result.isUserManaged()).isTrue();
- assertThat(result.getWorstValue()).isNull();
- assertThat(result.getBestValue()).isNull();
- assertThat(result.isOptimizedBestValue()).isNull();
- assertThat(result.isDeleteHistoricalData()).isNull();
- assertThat(result.isHidden()).isNull();
- assertThat(result.isEnabled()).isTrue();
- }
-
- @Test
- public void find_all_enabled() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- assertThat(dao.selectEnabled(session)).hasSize(2);
- }
-
- @Test
- public void insert() {
- dao.insert(session, new MetricDto()
- .setId(1)
- .setKey("coverage")
- .setShortName("Coverage")
- .setDescription("Coverage by unit tests")
- .setDomain("Tests")
- .setValueType("PERCENT")
- .setQualitative(true)
- .setUserManaged(true)
- .setWorstValue(0d)
- .setBestValue(100d)
- .setOptimizedBestValue(true)
- .setDirection(1)
- .setOrigin("JAV")
- .setHidden(true)
- .setDeleteHistoricalData(true)
- .setEnabled(true));
-
- MetricDto result = dao.selectByKey(session, "coverage");
- assertThat(result.getId()).isNotNull();
- assertThat(result.getKey()).isEqualTo("coverage");
- assertThat(result.getShortName()).isEqualTo("Coverage");
- assertThat(result.getDescription()).isEqualTo("Coverage by unit tests");
- assertThat(result.getDomain()).isEqualTo("Tests");
- assertThat(result.getValueType()).isEqualTo("PERCENT");
- assertThat(result.getOrigin()).isEqualTo("JAV");
- assertThat(result.getDirection()).isEqualTo(1);
- assertThat(result.isQualitative()).isTrue();
- assertThat(result.isUserManaged()).isTrue();
- assertThat(result.getWorstValue()).isEqualTo(0d);
- assertThat(result.getBestValue()).isEqualTo(100d);
- assertThat(result.isOptimizedBestValue()).isTrue();
- assertThat(result.isDeleteHistoricalData()).isTrue();
- assertThat(result.isHidden()).isTrue();
- assertThat(result.isEnabled()).isTrue();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.ws;
-
-import org.apache.commons.lang.StringUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.sonar.api.server.ws.WebService.Param;
-import org.sonar.core.measure.db.MetricDto;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.DbTester;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.measure.persistence.MetricDao;
-import org.sonar.server.ws.WsTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.measure.ws.ListAction.PARAM_IS_CUSTOM;
-
-public class ListActionTest {
-
- @ClassRule
- public static DbTester db = new DbTester();
- DbClient dbClient;
- DbSession dbSession;
- WsTester ws;
-
- @Before
- public void setUp() {
- dbClient = new DbClient(db.database(), db.myBatis(), new MetricDao());
- dbSession = dbClient.openSession(false);
- ws = new WsTester(new MetricsWs(new ListAction(dbClient)));
- db.truncateTables();
- }
-
- @After
- public void tearDown() {
- dbSession.close();
- }
-
- @Test
- public void list_metrics_in_database() throws Exception {
- insertNewCustomMetric("1", "2", "3");
-
- WsTester.Result result = newRequest().execute();
-
- result.assertJson(getClass(), "list_metrics.json");
- }
-
- @Test
- public void list_metrics_ordered_by_name_case_insensitive() throws Exception {
- insertNewCustomMetric("3", "1", "2");
-
- String firstResult = newRequest().setParam(Param.PAGE, "1").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
- String secondResult = newRequest().setParam(Param.PAGE, "2").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
- String thirdResult = newRequest().setParam(Param.PAGE, "3").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
-
- assertThat(firstResult).contains("custom-key-1").doesNotContain("custom-key-2").doesNotContain("custom-key-3");
- assertThat(secondResult).contains("custom-key-2").doesNotContain("custom-key-1").doesNotContain("custom-key-3");
- assertThat(thirdResult).contains("custom-key-3").doesNotContain("custom-key-1").doesNotContain("custom-key-2");
- }
-
- @Test
- public void list_metrics_with_pagination() throws Exception {
- insertNewCustomMetric("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
-
- WsTester.Result result = newRequest()
- .setParam(Param.PAGE, "3")
- .setParam(Param.PAGE_SIZE, "4")
- .execute();
-
- assertThat(StringUtils.countMatches(result.outputAsString(), "custom-key")).isEqualTo(2);
- }
-
- @Test
- public void list_metric_with_is_custom_true() throws Exception {
- insertNewCustomMetric("1", "2");
- insertNewNonCustomMetric("3");
-
- String result = newRequest()
- .setParam(PARAM_IS_CUSTOM, "true").execute().outputAsString();
-
- assertThat(result).contains("custom-key-1", "custom-key-2")
- .doesNotContain("non-custom-key-3");
- }
-
- @Test
- public void list_metric_with_is_custom_false() throws Exception {
- insertNewCustomMetric("1", "2");
- insertNewNonCustomMetric("3");
-
- String result = newRequest()
- .setParam(PARAM_IS_CUSTOM, "false").execute().outputAsString();
-
- assertThat(result).doesNotContain("custom-key-1")
- .doesNotContain("custom-key-2")
- .contains("non-custom-key-3");
- }
-
- @Test
- public void list_metric_with_chosen_fields() throws Exception {
- insertNewCustomMetric("1");
-
- String result = newRequest().setParam(Param.FIELDS, "name").execute().outputAsString();
-
- assertThat(result).contains("id", "key", "name")
- .doesNotContain("domain")
- .doesNotContain("description")
- .doesNotContain("type");
- }
-
- private void insertNewNonCustomMetric(String... ids) {
- for (String id : ids) {
- dbClient.metricDao().insert(dbSession, MetricTesting.newDto()
- .setKey("non-custom-key-" + id)
- .setEnabled(true)
- .setUserManaged(false));
- }
- dbSession.commit();
- }
-
- private void insertNewCustomMetric(String... ids) {
- for (String id : ids) {
- dbClient.metricDao().insert(dbSession, newCustomMetric(id));
- }
- dbSession.commit();
- }
-
- private MetricDto newCustomMetric(String id) {
- return MetricTesting.newDto()
- .setKey("custom-key-" + id)
- .setShortName("custom-name-" + id)
- .setDomain("custom-domain-" + id)
- .setDescription("custom-description-" + id)
- .setValueType("INT")
- .setUserManaged(true)
- .setEnabled(true);
- }
-
- private WsTester.TestRequest newRequest() {
- return ws.newGetRequest("api/metrics", "list");
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.ws;
-
-import org.apache.commons.lang.RandomStringUtils;
-import org.apache.commons.lang.math.RandomUtils;
-import org.sonar.api.measures.Metric;
-import org.sonar.core.measure.db.MetricDto;
-
-public class MetricTesting {
- private MetricTesting() {
- // static stuff only
- }
-
- public static MetricDto newDto() {
- Metric.ValueType[] metricTypes = Metric.ValueType.values();
- return new MetricDto()
- .setId(RandomUtils.nextInt())
- .setKey(RandomStringUtils.randomAlphanumeric(64))
- .setShortName(RandomStringUtils.randomAlphanumeric(64))
- .setValueType(metricTypes[RandomUtils.nextInt(metricTypes.length - 1)].name())
- .setDomain(RandomStringUtils.randomAlphanumeric(64))
- .setDescription(RandomStringUtils.randomAlphanumeric(250))
- .setBestValue(RandomUtils.nextDouble())
- .setDeleteHistoricalData(RandomUtils.nextBoolean())
- .setDirection(RandomUtils.nextInt())
- .setHidden(RandomUtils.nextBoolean())
- .setEnabled(RandomUtils.nextBoolean())
- .setOptimizedBestValue(RandomUtils.nextBoolean())
- .setQualitative(RandomUtils.nextBoolean())
- .setOrigin(RandomStringUtils.randomAlphabetic(3))
- .setUserManaged(RandomUtils.nextBoolean())
- .setWorstValue(RandomUtils.nextDouble());
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.ws;
-
-import org.junit.Test;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.server.ws.WsTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class MetricsWsTest {
-
- WsTester tester = new WsTester(new MetricsWs());
-
- @Test
- public void define_ws() {
- WebService.Controller controller = tester.controller("api/metrics");
- assertThat(controller).isNotNull();
- assertThat(controller.description()).isNotEmpty();
- assertThat(controller.actions()).hasSize(1);
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.metric.persistence;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.core.metric.db.MetricDto;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class MetricDaoTest {
+
+ @ClassRule
+ public static DbTester dbTester = new DbTester();
+
+ DbSession session;
+
+ MetricDao dao;
+
+ @Before
+ public void createDao() {
+ dbTester.truncateTables();
+ session = dbTester.myBatis().openSession(false);
+ dao = new MetricDao();
+ }
+
+ @After
+ public void tearDown() {
+ session.close();
+ }
+
+ @Test
+ public void get_by_key() {
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+ MetricDto result = dao.selectByKey(session, "coverage");
+ assertThat(result.getId()).isEqualTo(2);
+ assertThat(result.getKey()).isEqualTo("coverage");
+ assertThat(result.getShortName()).isEqualTo("Coverage");
+ assertThat(result.getDescription()).isEqualTo("Coverage by unit tests");
+ assertThat(result.getDomain()).isEqualTo("Tests");
+ assertThat(result.getValueType()).isEqualTo("PERCENT");
+ assertThat(result.getOrigin()).isEqualTo("JAV");
+ assertThat(result.getDirection()).isEqualTo(1);
+ assertThat(result.isQualitative()).isTrue();
+ assertThat(result.isUserManaged()).isFalse();
+ assertThat(result.getWorstValue()).isEqualTo(0d);
+ assertThat(result.getBestValue()).isEqualTo(100d);
+ assertThat(result.isOptimizedBestValue()).isFalse();
+ assertThat(result.isDeleteHistoricalData()).isFalse();
+ assertThat(result.isHidden()).isFalse();
+ assertThat(result.isEnabled()).isTrue();
+
+ // Disabled metrics are returned
+ result = dao.selectByKey(session, "disabled");
+ assertThat(result.getId()).isEqualTo(3);
+ assertThat(result.isEnabled()).isFalse();
+ }
+
+ @Test
+ public void get_manual_metric() {
+ dbTester.prepareDbUnit(getClass(), "manual_metric.xml");
+
+ MetricDto result = dao.selectByKey(session, "manual");
+ assertThat(result.getId()).isEqualTo(1);
+ assertThat(result.getKey()).isEqualTo("manual");
+ assertThat(result.getShortName()).isEqualTo("Manual metric");
+ assertThat(result.getDescription()).isEqualTo("Manual metric");
+ assertThat(result.getDomain()).isNullOrEmpty();
+ assertThat(result.getValueType()).isEqualTo("INT");
+ assertThat(result.getOrigin()).isEqualTo("GUI");
+ assertThat(result.getDirection()).isEqualTo(0);
+ assertThat(result.isQualitative()).isFalse();
+ assertThat(result.isUserManaged()).isTrue();
+ assertThat(result.getWorstValue()).isNull();
+ assertThat(result.getBestValue()).isNull();
+ assertThat(result.isOptimizedBestValue()).isNull();
+ assertThat(result.isDeleteHistoricalData()).isNull();
+ assertThat(result.isHidden()).isNull();
+ assertThat(result.isEnabled()).isTrue();
+ }
+
+ @Test
+ public void find_all_enabled() {
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+ assertThat(dao.selectEnabled(session)).hasSize(2);
+ }
+
+ @Test
+ public void insert() {
+ dao.insert(session, new MetricDto()
+ .setId(1)
+ .setKey("coverage")
+ .setShortName("Coverage")
+ .setDescription("Coverage by unit tests")
+ .setDomain("Tests")
+ .setValueType("PERCENT")
+ .setQualitative(true)
+ .setUserManaged(true)
+ .setWorstValue(0d)
+ .setBestValue(100d)
+ .setOptimizedBestValue(true)
+ .setDirection(1)
+ .setOrigin("JAV")
+ .setHidden(true)
+ .setDeleteHistoricalData(true)
+ .setEnabled(true));
+
+ MetricDto result = dao.selectByKey(session, "coverage");
+ assertThat(result.getId()).isNotNull();
+ assertThat(result.getKey()).isEqualTo("coverage");
+ assertThat(result.getShortName()).isEqualTo("Coverage");
+ assertThat(result.getDescription()).isEqualTo("Coverage by unit tests");
+ assertThat(result.getDomain()).isEqualTo("Tests");
+ assertThat(result.getValueType()).isEqualTo("PERCENT");
+ assertThat(result.getOrigin()).isEqualTo("JAV");
+ assertThat(result.getDirection()).isEqualTo(1);
+ assertThat(result.isQualitative()).isTrue();
+ assertThat(result.isUserManaged()).isTrue();
+ assertThat(result.getWorstValue()).isEqualTo(0d);
+ assertThat(result.getBestValue()).isEqualTo(100d);
+ assertThat(result.isOptimizedBestValue()).isTrue();
+ assertThat(result.isDeleteHistoricalData()).isTrue();
+ assertThat(result.isHidden()).isTrue();
+ assertThat(result.isEnabled()).isTrue();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.metric.ws;
+
+import org.apache.commons.lang.StringUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService.Param;
+import org.sonar.core.metric.db.MetricDto;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.metric.persistence.MetricDao;
+import org.sonar.server.ws.WsTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.metric.ws.ListAction.PARAM_IS_CUSTOM;
+
+public class ListActionTest {
+
+ @ClassRule
+ public static DbTester db = new DbTester();
+ DbClient dbClient;
+ DbSession dbSession;
+ WsTester ws;
+
+ @Before
+ public void setUp() {
+ dbClient = new DbClient(db.database(), db.myBatis(), new MetricDao());
+ dbSession = dbClient.openSession(false);
+ ws = new WsTester(new MetricsWs(new ListAction(dbClient)));
+ db.truncateTables();
+ }
+
+ @After
+ public void tearDown() {
+ dbSession.close();
+ }
+
+ @Test
+ public void list_metrics_in_database() throws Exception {
+ insertNewCustomMetric("1", "2", "3");
+
+ WsTester.Result result = newRequest().execute();
+
+ result.assertJson(getClass(), "list_metrics.json");
+ }
+
+ @Test
+ public void list_metrics_ordered_by_name_case_insensitive() throws Exception {
+ insertNewCustomMetric("3", "1", "2");
+
+ String firstResult = newRequest().setParam(Param.PAGE, "1").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
+ String secondResult = newRequest().setParam(Param.PAGE, "2").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
+ String thirdResult = newRequest().setParam(Param.PAGE, "3").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
+
+ assertThat(firstResult).contains("custom-key-1").doesNotContain("custom-key-2").doesNotContain("custom-key-3");
+ assertThat(secondResult).contains("custom-key-2").doesNotContain("custom-key-1").doesNotContain("custom-key-3");
+ assertThat(thirdResult).contains("custom-key-3").doesNotContain("custom-key-1").doesNotContain("custom-key-2");
+ }
+
+ @Test
+ public void list_metrics_with_pagination() throws Exception {
+ insertNewCustomMetric("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
+
+ WsTester.Result result = newRequest()
+ .setParam(Param.PAGE, "3")
+ .setParam(Param.PAGE_SIZE, "4")
+ .execute();
+
+ assertThat(StringUtils.countMatches(result.outputAsString(), "custom-key")).isEqualTo(2);
+ }
+
+ @Test
+ public void list_metric_with_is_custom_true() throws Exception {
+ insertNewCustomMetric("1", "2");
+ insertNewNonCustomMetric("3");
+
+ String result = newRequest()
+ .setParam(PARAM_IS_CUSTOM, "true").execute().outputAsString();
+
+ assertThat(result).contains("custom-key-1", "custom-key-2")
+ .doesNotContain("non-custom-key-3");
+ }
+
+ @Test
+ public void list_metric_with_is_custom_false() throws Exception {
+ insertNewCustomMetric("1", "2");
+ insertNewNonCustomMetric("3");
+
+ String result = newRequest()
+ .setParam(PARAM_IS_CUSTOM, "false").execute().outputAsString();
+
+ assertThat(result).doesNotContain("custom-key-1")
+ .doesNotContain("custom-key-2")
+ .contains("non-custom-key-3");
+ }
+
+ @Test
+ public void list_metric_with_chosen_fields() throws Exception {
+ insertNewCustomMetric("1");
+
+ String result = newRequest().setParam(Param.FIELDS, "name").execute().outputAsString();
+
+ assertThat(result).contains("id", "key", "name")
+ .doesNotContain("domain")
+ .doesNotContain("description")
+ .doesNotContain("type");
+ }
+
+ private void insertNewNonCustomMetric(String... ids) {
+ for (String id : ids) {
+ dbClient.metricDao().insert(dbSession, MetricTesting.newDto()
+ .setKey("non-custom-key-" + id)
+ .setEnabled(true)
+ .setUserManaged(false));
+ }
+ dbSession.commit();
+ }
+
+ private void insertNewCustomMetric(String... ids) {
+ for (String id : ids) {
+ dbClient.metricDao().insert(dbSession, newCustomMetric(id));
+ }
+ dbSession.commit();
+ }
+
+ private MetricDto newCustomMetric(String id) {
+ return MetricTesting.newDto()
+ .setKey("custom-key-" + id)
+ .setShortName("custom-name-" + id)
+ .setDomain("custom-domain-" + id)
+ .setDescription("custom-description-" + id)
+ .setValueType("INT")
+ .setUserManaged(true)
+ .setEnabled(true);
+ }
+
+ private WsTester.TestRequest newRequest() {
+ return ws.newGetRequest("api/metrics", "list");
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.metric.ws;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang.math.RandomUtils;
+import org.sonar.api.measures.Metric;
+import org.sonar.core.metric.db.MetricDto;
+
+public class MetricTesting {
+ private MetricTesting() {
+ // static stuff only
+ }
+
+ public static MetricDto newDto() {
+ Metric.ValueType[] metricTypes = Metric.ValueType.values();
+ return new MetricDto()
+ .setId(RandomUtils.nextInt())
+ .setKey(RandomStringUtils.randomAlphanumeric(64))
+ .setShortName(RandomStringUtils.randomAlphanumeric(64))
+ .setValueType(metricTypes[RandomUtils.nextInt(metricTypes.length - 1)].name())
+ .setDomain(RandomStringUtils.randomAlphanumeric(64))
+ .setDescription(RandomStringUtils.randomAlphanumeric(250))
+ .setBestValue(RandomUtils.nextDouble())
+ .setDeleteHistoricalData(RandomUtils.nextBoolean())
+ .setDirection(RandomUtils.nextInt())
+ .setHidden(RandomUtils.nextBoolean())
+ .setEnabled(RandomUtils.nextBoolean())
+ .setOptimizedBestValue(RandomUtils.nextBoolean())
+ .setQualitative(RandomUtils.nextBoolean())
+ .setOrigin(RandomStringUtils.randomAlphabetic(3))
+ .setUserManaged(RandomUtils.nextBoolean())
+ .setWorstValue(RandomUtils.nextDouble());
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.metric.ws;
+
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.ws.WsTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MetricsWsTest {
+
+ WsTester tester = new WsTester(new MetricsWs());
+
+ @Test
+ public void define_ws() {
+ WebService.Controller controller = tester.controller("api/metrics");
+ assertThat(controller).isNotNull();
+ assertThat(controller.description()).isNotEmpty();
+ assertThat(controller.actions()).hasSize(1);
+ }
+
+}
+++ /dev/null
-<dataset>
-
- <metrics id="1" name="manual" val_type="INT" description="Manual metric" domain="" short_name="Manual metric"
- qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="[null]"
- origin="GUI" delete_historical_data="[null]" user_managed="[true]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <metrics id="1" name="ncloc" val_type="INT" description="Non Commenting Lines of Code" domain="Size" short_name="Lines of code"
- qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="-1" hidden="[false]"
- origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
-
- <metrics id="2" name="coverage" val_type="PERCENT" description="Coverage by unit tests" domain="Tests" short_name="Coverage"
- qualitative="[true]" enabled="[true]" worst_value="0" optimized_best_value="[false]" best_value="100" direction="1" hidden="[false]"
- origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
-
- <metrics id="3" name="disabled" val_type="INT" description="[null]" domain="[null]" short_name="disabled"
- qualitative="[false]" enabled="[false]" worst_value="0" optimized_best_value="[true]" best_value="100" direction="1" hidden="[false]"
- origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
-
-</dataset>
+++ /dev/null
-{
- "metrics":[
- {
- "key":"custom-key-1",
- "name":"custom-name-1",
- "type":"Integer",
- "domain":"custom-domain-1",
- "description":"custom-description-1"
- },
- {
- "key":"custom-key-2",
- "name":"custom-name-2",
- "type":"Integer",
- "domain":"custom-domain-2",
- "description":"custom-description-2"
- },
- {
- "key":"custom-key-3",
- "name":"custom-name-3",
- "type":"Integer",
- "domain":"custom-domain-3",
- "description":"custom-description-3"
- }
- ]
-}
--- /dev/null
+<dataset>
+
+ <metrics id="1" name="manual" val_type="INT" description="Manual metric" domain="" short_name="Manual metric"
+ qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="[null]"
+ origin="GUI" delete_historical_data="[null]" user_managed="[true]"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <metrics id="1" name="ncloc" val_type="INT" description="Non Commenting Lines of Code" domain="Size" short_name="Lines of code"
+ qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="-1" hidden="[false]"
+ origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
+
+ <metrics id="2" name="coverage" val_type="PERCENT" description="Coverage by unit tests" domain="Tests" short_name="Coverage"
+ qualitative="[true]" enabled="[true]" worst_value="0" optimized_best_value="[false]" best_value="100" direction="1" hidden="[false]"
+ origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
+
+ <metrics id="3" name="disabled" val_type="INT" description="[null]" domain="[null]" short_name="disabled"
+ qualitative="[false]" enabled="[false]" worst_value="0" optimized_best_value="[true]" best_value="100" direction="1" hidden="[false]"
+ origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
+
+</dataset>
--- /dev/null
+{
+ "metrics":[
+ {
+ "key":"custom-key-1",
+ "name":"custom-name-1",
+ "type":"Integer",
+ "domain":"custom-domain-1",
+ "description":"custom-description-1"
+ },
+ {
+ "key":"custom-key-2",
+ "name":"custom-name-2",
+ "type":"Integer",
+ "domain":"custom-domain-2",
+ "description":"custom-description-2"
+ },
+ {
+ "key":"custom-key-3",
+ "name":"custom-name-3",
+ "type":"Integer",
+ "domain":"custom-domain-3",
+ "description":"custom-description-3"
+ }
+ ]
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.measure.db;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-public class MetricDto {
-
- private Integer id;
-
- private String name;
-
- private String shortName;
-
- private String valueType;
-
- private String description;
-
- private String domain;
-
- private int direction;
-
- private boolean qualitative;
-
- private boolean userManaged;
-
- private Double worstValue;
-
- private Double bestValue;
-
- private Boolean optimizedBestValue;
-
- private String origin;
-
- private Boolean hidden;
-
- private Boolean deleteHistoricalData;
-
- private boolean enabled;
-
- public Integer getId() {
- return id;
- }
-
- public MetricDto setId(Integer id) {
- this.id = id;
- return this;
- }
-
- public String getKey() {
- return name;
- }
-
- public MetricDto setKey(String name) {
- this.name = name;
- return this;
- }
-
- public String getShortName() {
- return shortName;
- }
-
- public MetricDto setShortName(String shortName) {
- this.shortName = shortName;
- return this;
- }
-
- public String getValueType() {
- return valueType;
- }
-
- public MetricDto setValueType(String valueType) {
- this.valueType = valueType;
- return this;
- }
-
- /**
- * @return null for manual metrics
- */
- @CheckForNull
- public String getDescription() {
- return description;
- }
-
- public MetricDto setDescription(@Nullable String description) {
- this.description = description;
- return this;
- }
-
- public String getDomain() {
- return domain;
- }
-
- public MetricDto setDomain(String domain) {
- this.domain = domain;
- return this;
- }
-
- public int getDirection() {
- return direction;
- }
-
- public MetricDto setDirection(int direction) {
- this.direction = direction;
- return this;
- }
-
- public boolean isQualitative() {
- return qualitative;
- }
-
- public MetricDto setQualitative(boolean qualitative) {
- this.qualitative = qualitative;
- return this;
- }
-
- public boolean isUserManaged() {
- return userManaged;
- }
-
- public MetricDto setUserManaged(boolean userManaged) {
- this.userManaged = userManaged;
- return this;
- }
-
- @CheckForNull
- public Double getWorstValue() {
- return worstValue;
- }
-
- public MetricDto setWorstValue(@Nullable Double worstValue) {
- this.worstValue = worstValue;
- return this;
- }
-
- @CheckForNull
- public Double getBestValue() {
- return bestValue;
- }
-
- public MetricDto setBestValue(@Nullable Double bestValue) {
- this.bestValue = bestValue;
- return this;
- }
-
- /**
- * @return null for manual metrics
- */
- @CheckForNull
- public Boolean isOptimizedBestValue() {
- return optimizedBestValue;
- }
-
- public MetricDto setOptimizedBestValue(@Nullable Boolean optimizedBestValue) {
- this.optimizedBestValue = optimizedBestValue;
- return this;
- }
-
- public String getOrigin() {
- return origin;
- }
-
- public MetricDto setOrigin(String origin) {
- this.origin = origin;
- return this;
- }
-
- /**
- * @return null for manual metrics
- */
- @CheckForNull
- public Boolean isHidden() {
- return hidden;
- }
-
- public MetricDto setHidden(@Nullable Boolean hidden) {
- this.hidden = hidden;
- return this;
- }
-
- /**
- * @return null for manual metrics
- */
- @CheckForNull
- public Boolean isDeleteHistoricalData() {
- return deleteHistoricalData;
- }
-
- public MetricDto setDeleteHistoricalData(@Nullable Boolean deleteHistoricalData) {
- this.deleteHistoricalData = deleteHistoricalData;
- return this;
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public MetricDto setEnabled(boolean enabled) {
- this.enabled = enabled;
- return this;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.measure.db;
-
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.session.RowBounds;
-
-import java.util.List;
-import java.util.Map;
-
-public interface MetricMapper {
-
- MetricDto selectByKey(@Param("key") String key);
- List<MetricDto> selectAllEnabled();
- List<MetricDto> selectAllEnabled(Map<String, Object> properties, RowBounds rowBounds);
- void insert(MetricDto dto);
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.metric.db;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class MetricDto {
+
+ private Integer id;
+
+ private String name;
+
+ private String shortName;
+
+ private String valueType;
+
+ private String description;
+
+ private String domain;
+
+ private int direction;
+
+ private boolean qualitative;
+
+ private boolean userManaged;
+
+ private Double worstValue;
+
+ private Double bestValue;
+
+ private Boolean optimizedBestValue;
+
+ private String origin;
+
+ private Boolean hidden;
+
+ private Boolean deleteHistoricalData;
+
+ private boolean enabled;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public MetricDto setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ public String getKey() {
+ return name;
+ }
+
+ public MetricDto setKey(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String getShortName() {
+ return shortName;
+ }
+
+ public MetricDto setShortName(String shortName) {
+ this.shortName = shortName;
+ return this;
+ }
+
+ public String getValueType() {
+ return valueType;
+ }
+
+ public MetricDto setValueType(String valueType) {
+ this.valueType = valueType;
+ return this;
+ }
+
+ /**
+ * @return null for manual metrics
+ */
+ @CheckForNull
+ public String getDescription() {
+ return description;
+ }
+
+ public MetricDto setDescription(@Nullable String description) {
+ this.description = description;
+ return this;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public MetricDto setDomain(String domain) {
+ this.domain = domain;
+ return this;
+ }
+
+ public int getDirection() {
+ return direction;
+ }
+
+ public MetricDto setDirection(int direction) {
+ this.direction = direction;
+ return this;
+ }
+
+ public boolean isQualitative() {
+ return qualitative;
+ }
+
+ public MetricDto setQualitative(boolean qualitative) {
+ this.qualitative = qualitative;
+ return this;
+ }
+
+ public boolean isUserManaged() {
+ return userManaged;
+ }
+
+ public MetricDto setUserManaged(boolean userManaged) {
+ this.userManaged = userManaged;
+ return this;
+ }
+
+ @CheckForNull
+ public Double getWorstValue() {
+ return worstValue;
+ }
+
+ public MetricDto setWorstValue(@Nullable Double worstValue) {
+ this.worstValue = worstValue;
+ return this;
+ }
+
+ @CheckForNull
+ public Double getBestValue() {
+ return bestValue;
+ }
+
+ public MetricDto setBestValue(@Nullable Double bestValue) {
+ this.bestValue = bestValue;
+ return this;
+ }
+
+ /**
+ * @return null for manual metrics
+ */
+ @CheckForNull
+ public Boolean isOptimizedBestValue() {
+ return optimizedBestValue;
+ }
+
+ public MetricDto setOptimizedBestValue(@Nullable Boolean optimizedBestValue) {
+ this.optimizedBestValue = optimizedBestValue;
+ return this;
+ }
+
+ public String getOrigin() {
+ return origin;
+ }
+
+ public MetricDto setOrigin(String origin) {
+ this.origin = origin;
+ return this;
+ }
+
+ /**
+ * @return null for manual metrics
+ */
+ @CheckForNull
+ public Boolean isHidden() {
+ return hidden;
+ }
+
+ public MetricDto setHidden(@Nullable Boolean hidden) {
+ this.hidden = hidden;
+ return this;
+ }
+
+ /**
+ * @return null for manual metrics
+ */
+ @CheckForNull
+ public Boolean isDeleteHistoricalData() {
+ return deleteHistoricalData;
+ }
+
+ public MetricDto setDeleteHistoricalData(@Nullable Boolean deleteHistoricalData) {
+ this.deleteHistoricalData = deleteHistoricalData;
+ return this;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public MetricDto setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ return this;
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.metric.db;
+
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.RowBounds;
+
+import java.util.List;
+import java.util.Map;
+
+public interface MetricMapper {
+
+ MetricDto selectByKey(@Param("key") String key);
+ List<MetricDto> selectAllEnabled();
+ List<MetricDto> selectAllEnabled(Map<String, Object> properties, RowBounds rowBounds);
+ void insert(MetricDto dto);
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.core.metric.db;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
import org.sonar.core.measure.db.MeasureFilterDto;
import org.sonar.core.measure.db.MeasureFilterMapper;
import org.sonar.core.measure.db.MeasureMapper;
-import org.sonar.core.measure.db.MetricMapper;
+import org.sonar.core.metric.db.MetricMapper;
import org.sonar.core.notification.db.NotificationQueueDto;
import org.sonar.core.notification.db.NotificationQueueMapper;
import org.sonar.core.permission.GroupWithPermissionDto;
--- /dev/null
+<dataset>
+
+ <measure_filters
+ id="1"
+ name="Projects"
+ user_id="[null]"
+ shared="[true]"
+ description="All projects"
+ data="qualifiers=TRK"
+ created_at="2012-12-25"
+ updated_at="2012-12-25" />
+
+ <measure_filters
+ id="2"
+ name="Files"
+ user_id="[null]"
+ shared="[true]"
+ description="All files"
+ data="qualifiers=FIL"
+ created_at="2012-01-25"
+ updated_at="2012-01-25" />
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <measure_filters
+ id="1"
+ name="Projects"
+ user_id="[null]"
+ shared="[true]"
+ description="All projects"
+ data="qualifiers=TRK"
+ created_at="2012-12-25"
+ updated_at="2012-12-25"/>
+
+ <measure_filters
+ id="2"
+ name="Files"
+ user_id="[null]"
+ shared="[true]"
+ description="All files"
+ data="qualifiers=FIL"
+ created_at="2012-01-25"
+ updated_at="2012-01-25"/>
+
+
+ <measure_filters
+ id="3"
+ name="Project Treemap"
+ user_id="123"
+ shared="[true]"
+ description="Treemap of projects"
+ data="qualifiers=TRK|display=treemap"
+ created_at="2012-12-25"
+ updated_at="2012-12-25"/>
+
+</dataset>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.measure.db.MetricMapper">
-
- <sql id="metricColumns">
- m.id,
- m.name,
- m.description,
- m.direction,
- m.domain,
- m.short_name as shortName,
- m.qualitative,
- m.val_type as valueType,
- m.user_managed as userManaged,
- m.enabled,
- m.origin,
- m.worst_value as worstValue,
- m.best_value as bestValue,
- m.optimized_best_value as optimizedBestValue,
- m.hidden,
- m.delete_historical_data as deleteHistoricalData
- </sql>
-
- <select id="selectByKey" parameterType="map" resultType="org.sonar.core.measure.db.MetricDto">
- SELECT
- <include refid="metricColumns"/>
- FROM metrics m
- <where>
- AND m.name=#{key}
- </where>
- </select>
-
- <select id="selectAllEnabled" parameterType="map" resultType="org.sonar.core.measure.db.MetricDto">
- SELECT
- <include refid="metricColumns"/>
- FROM metrics m
- <where>
- AND m.enabled=${_true}
- <if test="isCustom!=null">
- <if test="isCustom.equals(true)">
- AND m.user_managed=${_true}
- </if>
- <if test="isCustom.equals(false)">
- AND m.user_managed=${_false}
- </if>
- </if>
- </where>
- ORDER BY UPPER(m.short_name)
- </select>
-
- <insert id="insert" parameterType="org.sonar.core.measure.db.MetricDto" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
- INSERT INTO metrics (
- name, description, direction, domain, short_name, qualitative, val_type, user_managed, enabled, origin, worst_value, best_value, optimized_best_value, hidden, delete_historical_data)
- VALUES (
- #{name, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{direction, jdbcType=INTEGER},
- #{domain, jdbcType=VARCHAR}, #{shortName, jdbcType=VARCHAR}, #{qualitative, jdbcType=BOOLEAN},
- #{valueType, jdbcType=VARCHAR}, #{userManaged, jdbcType=BOOLEAN}, #{enabled, jdbcType=BOOLEAN},
- #{origin, jdbcType=VARCHAR}, #{worstValue, jdbcType=DOUBLE}, #{bestValue, jdbcType=DOUBLE},
- #{optimizedBestValue, jdbcType=BOOLEAN}, #{hidden, jdbcType=BOOLEAN}, #{deleteHistoricalData, jdbcType=BOOLEAN}
- )
- </insert>
-
-</mapper>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.metric.db.MetricMapper">
+
+ <sql id="metricColumns">
+ m.id,
+ m.name,
+ m.description,
+ m.direction,
+ m.domain,
+ m.short_name as shortName,
+ m.qualitative,
+ m.val_type as valueType,
+ m.user_managed as userManaged,
+ m.enabled,
+ m.origin,
+ m.worst_value as worstValue,
+ m.best_value as bestValue,
+ m.optimized_best_value as optimizedBestValue,
+ m.hidden,
+ m.delete_historical_data as deleteHistoricalData
+ </sql>
+
+ <select id="selectByKey" parameterType="map" resultType="org.sonar.core.metric.db.MetricDto">
+ SELECT
+ <include refid="metricColumns"/>
+ FROM metrics m
+ <where>
+ AND m.name=#{key}
+ </where>
+ </select>
+
+ <select id="selectAllEnabled" parameterType="map" resultType="org.sonar.core.metric.db.MetricDto">
+ SELECT
+ <include refid="metricColumns"/>
+ FROM metrics m
+ <where>
+ AND m.enabled=${_true}
+ <if test="isCustom!=null">
+ <if test="isCustom.equals(true)">
+ AND m.user_managed=${_true}
+ </if>
+ <if test="isCustom.equals(false)">
+ AND m.user_managed=${_false}
+ </if>
+ </if>
+ </where>
+ ORDER BY UPPER(m.short_name)
+ </select>
+
+ <insert id="insert" parameterType="org.sonar.core.metric.db.MetricDto" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
+ INSERT INTO metrics (
+ name, description, direction, domain, short_name, qualitative, val_type, user_managed, enabled, origin, worst_value, best_value, optimized_best_value, hidden, delete_historical_data)
+ VALUES (
+ #{name, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{direction, jdbcType=INTEGER},
+ #{domain, jdbcType=VARCHAR}, #{shortName, jdbcType=VARCHAR}, #{qualitative, jdbcType=BOOLEAN},
+ #{valueType, jdbcType=VARCHAR}, #{userManaged, jdbcType=BOOLEAN}, #{enabled, jdbcType=BOOLEAN},
+ #{origin, jdbcType=VARCHAR}, #{worstValue, jdbcType=DOUBLE}, #{bestValue, jdbcType=DOUBLE},
+ #{optimizedBestValue, jdbcType=BOOLEAN}, #{hidden, jdbcType=BOOLEAN}, #{deleteHistoricalData, jdbcType=BOOLEAN}
+ )
+ </insert>
+
+</mapper>
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.measure.db;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class MetricDtoTest {
-
- @Test
- public void getters_and_setters() {
- MetricDto metricDto = new MetricDto()
- .setId(1)
- .setKey("coverage")
- .setShortName("Coverage")
- .setDescription("Coverage by unit tests")
- .setDomain("Tests")
- .setValueType("PERCENT")
- .setQualitative(true)
- .setUserManaged(false)
- .setWorstValue(0d)
- .setBestValue(100d)
- .setOptimizedBestValue(true)
- .setDirection(1)
- .setOrigin("JAV")
- .setHidden(true)
- .setDeleteHistoricalData(true)
- .setEnabled(true);
-
- assertThat(metricDto.getId()).isEqualTo(1);
- assertThat(metricDto.getKey()).isEqualTo("coverage");
- assertThat(metricDto.getShortName()).isEqualTo("Coverage");
- assertThat(metricDto.getDescription()).isEqualTo("Coverage by unit tests");
- assertThat(metricDto.getDomain()).isEqualTo("Tests");
- assertThat(metricDto.getValueType()).isEqualTo("PERCENT");
- assertThat(metricDto.isQualitative()).isTrue();
- assertThat(metricDto.isUserManaged()).isFalse();
- assertThat(metricDto.getWorstValue()).isEqualTo(0d);
- assertThat(metricDto.getBestValue()).isEqualTo(100d);
- assertThat(metricDto.isOptimizedBestValue()).isTrue();
- assertThat(metricDto.getDirection()).isEqualTo(1);
- assertThat(metricDto.getOrigin()).isEqualTo("JAV");
- assertThat(metricDto.isHidden()).isTrue();
- assertThat(metricDto.isDeleteHistoricalData()).isTrue();
- assertThat(metricDto.isEnabled()).isTrue();
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.metric.db;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MetricDtoTest {
+
+ @Test
+ public void getters_and_setters() {
+ MetricDto metricDto = new MetricDto()
+ .setId(1)
+ .setKey("coverage")
+ .setShortName("Coverage")
+ .setDescription("Coverage by unit tests")
+ .setDomain("Tests")
+ .setValueType("PERCENT")
+ .setQualitative(true)
+ .setUserManaged(false)
+ .setWorstValue(0d)
+ .setBestValue(100d)
+ .setOptimizedBestValue(true)
+ .setDirection(1)
+ .setOrigin("JAV")
+ .setHidden(true)
+ .setDeleteHistoricalData(true)
+ .setEnabled(true);
+
+ assertThat(metricDto.getId()).isEqualTo(1);
+ assertThat(metricDto.getKey()).isEqualTo("coverage");
+ assertThat(metricDto.getShortName()).isEqualTo("Coverage");
+ assertThat(metricDto.getDescription()).isEqualTo("Coverage by unit tests");
+ assertThat(metricDto.getDomain()).isEqualTo("Tests");
+ assertThat(metricDto.getValueType()).isEqualTo("PERCENT");
+ assertThat(metricDto.isQualitative()).isTrue();
+ assertThat(metricDto.isUserManaged()).isFalse();
+ assertThat(metricDto.getWorstValue()).isEqualTo(0d);
+ assertThat(metricDto.getBestValue()).isEqualTo(100d);
+ assertThat(metricDto.isOptimizedBestValue()).isTrue();
+ assertThat(metricDto.getDirection()).isEqualTo(1);
+ assertThat(metricDto.getOrigin()).isEqualTo("JAV");
+ assertThat(metricDto.isHidden()).isTrue();
+ assertThat(metricDto.isDeleteHistoricalData()).isTrue();
+ assertThat(metricDto.isEnabled()).isTrue();
+ }
+}
+++ /dev/null
-<dataset>
-
- <measure_filters
- id="1"
- name="Projects"
- user_id="[null]"
- shared="[true]"
- description="All projects"
- data="qualifiers=TRK"
- created_at="2012-12-25"
- updated_at="2012-12-25" />
-
- <measure_filters
- id="2"
- name="Files"
- user_id="[null]"
- shared="[true]"
- description="All files"
- data="qualifiers=FIL"
- created_at="2012-01-25"
- updated_at="2012-01-25" />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <measure_filters
- id="1"
- name="Projects"
- user_id="[null]"
- shared="[true]"
- description="All projects"
- data="qualifiers=TRK"
- created_at="2012-12-25"
- updated_at="2012-12-25"/>
-
- <measure_filters
- id="2"
- name="Files"
- user_id="[null]"
- shared="[true]"
- description="All files"
- data="qualifiers=FIL"
- created_at="2012-01-25"
- updated_at="2012-01-25"/>
-
-
- <measure_filters
- id="3"
- name="Project Treemap"
- user_id="123"
- shared="[true]"
- description="Treemap of projects"
- data="qualifiers=TRK|display=treemap"
- created_at="2012-12-25"
- updated_at="2012-12-25"/>
-
-</dataset>