Search in sources :

Example 66 with MetricDto

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

the class CreateAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn().checkIsSystemAdministrator();
    String key = request.mandatoryParam(PARAM_KEY);
    try (DbSession dbSession = dbClient.openSession(false)) {
        MetricDto metricTemplate = newMetricTemplate(request);
        MetricDto metricInDb = dbClient.metricDao().selectByKey(dbSession, key);
        checkMetricInDbAndTemplate(dbSession, metricInDb, metricTemplate);
        if (metricIsNotInDb(metricInDb)) {
            metricInDb = insertNewMetric(dbSession, metricTemplate);
        } else {
            updateMetric(dbSession, metricInDb, metricTemplate);
        }
        JsonWriter json = response.newJsonWriter();
        writeMetric(json, metricInDb);
        json.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 67 with MetricDto

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

the class SearchAction method handle.

@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);
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions.getOffset(), searchOptions.getLimit());
        int nbMetrics = dbClient.metricDao().countEnabled(dbSession, isCustom);
        JsonWriter json = response.newJsonWriter();
        json.beginObject();
        Set<String> desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS));
        writeMetrics(json, metrics, desiredFields);
        searchOptions.writeJson(json, nbMetrics);
        json.endObject();
        json.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) SearchOptions(org.sonar.server.es.SearchOptions) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 68 with MetricDto

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

the class UpdateAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn().checkIsSystemAdministrator();
    int id = request.mandatoryParamAsInt(PARAM_ID);
    try (DbSession dbSession = dbClient.openSession(false)) {
        MetricDto metricTemplate = newMetricTemplate(request);
        MetricDto metricInDb = dbClient.metricDao().selectById(dbSession, id);
        checkMetricInDbAndTemplate(dbSession, metricInDb, metricTemplate);
        updateMetricInDb(dbSession, metricInDb, metricTemplate);
        JsonWriter json = response.newJsonWriter();
        writeMetric(json, metricInDb);
        json.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 69 with MetricDto

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

the class ComponentTreeDataLoader method searchMeasuresByComponentUuidAndMetric.

private Table<String, MetricDto, MeasureDto> searchMeasuresByComponentUuidAndMetric(DbSession dbSession, ComponentDto baseComponent, ComponentTreeQuery componentTreeQuery, List<ComponentDto> components, List<MetricDto> metrics, @Nullable Long developerId) {
    Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId);
    MeasureTreeQuery measureQuery = MeasureTreeQuery.builder().setStrategy(MeasureTreeQuery.Strategy.valueOf(componentTreeQuery.getStrategy().name())).setNameOrKeyQuery(componentTreeQuery.getNameOrKeyQuery()).setQualifiers(componentTreeQuery.getQualifiers()).setPersonId(developerId).setMetricIds(new ArrayList<>(metricsById.keySet())).build();
    List<MeasureDto> measureDtos = dbClient.measureDao().selectTreeByQuery(dbSession, baseComponent, measureQuery);
    Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric = HashBasedTable.create(components.size(), metrics.size());
    for (MeasureDto measureDto : measureDtos) {
        measuresByComponentUuidAndMetric.put(measureDto.getComponentUuid(), metricsById.get(measureDto.getMetricId()), measureDto);
    }
    addBestValuesToMeasures(measuresByComponentUuidAndMetric, components, metrics);
    return measuresByComponentUuidAndMetric;
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MeasureTreeQuery(org.sonar.db.measure.MeasureTreeQuery) MetricDto(org.sonar.db.metric.MetricDto) ArrayList(java.util.ArrayList)

Example 70 with MetricDto

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

the class SearchHistoryAction method searchMeasures.

private List<MeasureDto> searchMeasures(DbSession dbSession, SearchHistoryRequest request, SearchHistoryResult result) {
    Date from = parseStartingDateOrDateTime(request.getFrom());
    Date to = parseEndingDateOrDateTime(request.getTo());
    PastMeasureQuery dbQuery = new PastMeasureQuery(result.getComponent().uuid(), result.getMetrics().stream().map(MetricDto::getId).collect(Collectors.toList()), from == null ? null : from.getTime(), to == null ? null : (to.getTime() + 1_000L));
    return dbClient.measureDao().selectPastMeasures(dbSession, dbQuery);
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) PastMeasureQuery(org.sonar.db.measure.PastMeasureQuery) Date(java.util.Date)

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