Search in sources :

Example 16 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class CreateAction method newMetricTemplate.

private static MetricDto newMetricTemplate(Request request) {
    String key = checkMetricKeyFormat(request.mandatoryParam(PARAM_KEY));
    String name = request.mandatoryParam(PARAM_NAME);
    String type = Metric.ValueType.valueOf(request.mandatoryParam(PARAM_TYPE)).name();
    String domain = request.param(PARAM_DOMAIN);
    String description = request.param(PARAM_DESCRIPTION);
    MetricDto metricTemplate = new MetricDto().setKey(key).setShortName(name).setValueType(type);
    if (domain != null) {
        metricTemplate.setDomain(domain);
    }
    if (description != null) {
        metricTemplate.setDescription(description);
    }
    return metricTemplate;
}
Also used : MetricDto(org.sonar.db.metric.MetricDto)

Example 17 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class MetricJsonWriter method write.

public static void write(JsonWriter json, List<MetricDto> metrics, Set<String> fieldsToReturn) {
    json.name("metrics");
    json.beginArray();
    for (MetricDto metric : metrics) {
        write(json, metric, fieldsToReturn);
    }
    json.endArray();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto)

Example 18 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class UpdateAction method checkNoOtherMetricWithTargetKey.

private void checkNoOtherMetricWithTargetKey(DbSession dbSession, MetricDto metricInDb, MetricDto template) {
    String targetKey = template.getKey();
    MetricDto metricWithTargetKey = dbClient.metricDao().selectByKey(dbSession, targetKey);
    checkRequest(!isMetricFoundInDb(metricWithTargetKey) || metricInDb.getId().equals(metricWithTargetKey.getId()), "The key '%s' is already used by an existing metric.", targetKey);
}
Also used : MetricDto(org.sonar.db.metric.MetricDto)

Example 19 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class UpdateAction method newMetricTemplate.

private static MetricDto newMetricTemplate(Request request) {
    int id = request.mandatoryParamAsInt(PARAM_ID);
    String key = request.param(PARAM_KEY);
    if (key != null) {
        MetricKeyValidator.checkMetricKeyFormat(key);
    }
    String type = request.param(PARAM_TYPE);
    String name = request.param(PARAM_NAME);
    String domain = request.param(PARAM_DOMAIN);
    String description = request.param(PARAM_DESCRIPTION);
    MetricDto metricTemplate = new MetricDto().setId(id);
    if (key != null) {
        metricTemplate.setKey(key);
    }
    if (type != null) {
        metricTemplate.setValueType(type);
    }
    if (name != null) {
        metricTemplate.setShortName(name);
    }
    if (domain != null) {
        metricTemplate.setDomain(domain);
    }
    if (description != null) {
        metricTemplate.setDescription(description);
    }
    return metricTemplate;
}
Also used : MetricDto(org.sonar.db.metric.MetricDto)

Example 20 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class SearchMyProjectsDataLoader method load.

SearchMyProjectsData load(DbSession dbSession, SearchMyProjectsRequest request) {
    SearchMyProjectsData.Builder data = builder();
    ProjectsResult searchResult = searchProjects(dbSession, request);
    List<ComponentDto> projects = searchResult.projects;
    List<String> projectUuids = Lists.transform(projects, ComponentDto::projectUuid);
    List<ComponentLinkDto> projectLinks = dbClient.componentLinkDao().selectByComponentUuids(dbSession, projectUuids);
    List<SnapshotDto> snapshots = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, projectUuids);
    MetricDto gateStatusMetric = dbClient.metricDao().selectOrFailByKey(dbSession, CoreMetrics.ALERT_STATUS_KEY);
    MeasureQuery measureQuery = MeasureQuery.builder().setProjectUuids(projectUuids).setMetricId(gateStatusMetric.getId()).build();
    List<MeasureDto> qualityGates = dbClient.measureDao().selectByQuery(dbSession, measureQuery);
    data.setProjects(projects).setProjectLinks(projectLinks).setSnapshots(snapshots).setQualityGates(qualityGates).setTotalNbOfProjects(searchResult.total);
    return data.build();
}
Also used : ComponentLinkDto(org.sonar.db.component.ComponentLinkDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) MeasureDto(org.sonar.db.measure.MeasureDto) MetricDto(org.sonar.db.metric.MetricDto) MeasureQuery(org.sonar.db.measure.MeasureQuery)

Aggregations

MetricDto (org.sonar.db.metric.MetricDto)137 Test (org.junit.Test)83 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)61 ComponentDto (org.sonar.db.component.ComponentDto)49 SnapshotDto (org.sonar.db.component.SnapshotDto)33 CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)26 DbSession (org.sonar.db.DbSession)11 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)11 CustomMeasureTesting.newCustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto)10 MeasureDto (org.sonar.db.measure.MeasureDto)9 OrganizationDto (org.sonar.db.organization.OrganizationDto)8 ProjectMeasures (org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures)7 QualityGateConditionDto (org.sonar.db.qualitygate.QualityGateConditionDto)6 JsonWriter (org.sonar.api.utils.text.JsonWriter)5 WsTester (org.sonar.server.ws.WsTester)5 SearchWsResponse (org.sonarqube.ws.WsMeasures.SearchWsResponse)5 MeasureQuery (org.sonar.db.measure.MeasureQuery)3 UserDto (org.sonar.db.user.UserDto)3 WsMeasures (org.sonarqube.ws.WsMeasures)3 ComponentWsResponse (org.sonarqube.ws.WsMeasures.ComponentWsResponse)3