Search in sources :

Example 1 with CustomMeasureDto

use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.

the class CustomMeasuresCopyStep method copy.

private void copy(Component component) {
    for (CustomMeasureDto dto : loadCustomMeasures(component)) {
        Metric metric = metricRepository.getById(dto.getMetricId());
        // else metric is not found and an exception is raised
        Measure measure = dtoToMeasure(dto, metric);
        measureRepository.add(component, metric, measure);
    }
}
Also used : Measure(org.sonar.server.computation.task.projectanalysis.measure.Measure) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto)

Example 2 with CustomMeasureDto

use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.

the class CreateAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String valueAsString = request.mandatoryParam(PARAM_VALUE);
    String description = request.param(PARAM_DESCRIPTION);
    long now = system.now();
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.param(PARAM_PROJECT_ID), request.param(PARAM_PROJECT_KEY), PROJECT_ID_AND_KEY);
        MetricDto metric = searchMetric(dbSession, request);
        checkPermissions(userSession, component);
        checkIsProjectOrModule(component);
        checkMeasureDoesNotExistAlready(dbSession, component, metric);
        UserDto user = dbClient.userDao().selectOrFailByLogin(dbSession, userSession.getLogin());
        CustomMeasureDto measure = new CustomMeasureDto().setComponentUuid(component.uuid()).setMetricId(metric.getId()).setDescription(description).setUserLogin(user.getLogin()).setCreatedAt(now).setUpdatedAt(now);
        validator.setMeasureValue(measure, valueAsString, metric);
        dbClient.customMeasureDao().insert(dbSession, measure);
        dbSession.commit();
        JsonWriter json = response.newJsonWriter();
        customMeasureJsonWriter.write(json, measure, metric, component, user, true, CustomMeasureJsonWriter.OPTIONAL_FIELDS);
        json.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) JsonWriter(org.sonar.api.utils.text.JsonWriter) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto)

Example 3 with CustomMeasureDto

use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.

the class CustomMeasureJsonWriter method write.

public void write(JsonWriter json, List<CustomMeasureDto> customMeasures, ComponentDto project, Map<Integer, MetricDto> metricsById, Map<String, UserDto> usersByLogin, @Nullable Long lastAnalysisTimestamp, Collection<String> fieldsToReturn) {
    json.name("customMeasures");
    json.beginArray();
    for (CustomMeasureDto customMeasure : customMeasures) {
        boolean pending = lastAnalysisTimestamp == null || lastAnalysisTimestamp < customMeasure.getUpdatedAt();
        write(json, customMeasure, metricsById.get(customMeasure.getMetricId()), project, usersByLogin.get(customMeasure.getUserLogin()), pending, fieldsToReturn);
    }
    json.endArray();
}
Also used : CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto)

Example 4 with CustomMeasureDto

use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.

the class DeleteAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    long id = request.mandatoryParamAsLong(PARAM_ID);
    try (DbSession dbSession = dbClient.openSession(false)) {
        CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectOrFail(dbSession, id);
        checkPermission(dbSession, customMeasure);
        dbClient.customMeasureDao().delete(dbSession, id);
        dbSession.commit();
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto)

Example 5 with CustomMeasureDto

use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.

the class SearchAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String projectUuid = request.param(PARAM_PROJECT_ID);
    String projectKey = request.param(PARAM_PROJECT_KEY);
    List<String> fieldsToReturn = request.paramAsStrings(WebService.Param.FIELDS);
    SearchOptions searchOptions = new SearchOptions().setPage(request.mandatoryParamAsInt(WebService.Param.PAGE), request.mandatoryParamAsInt(WebService.Param.PAGE_SIZE));
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByUuidOrKey(dbSession, projectUuid, projectKey, PROJECT_ID_AND_KEY);
        checkPermissions(userSession, component);
        Long lastAnalysisDateMs = searchLastSnapshotDate(dbSession, component);
        List<CustomMeasureDto> customMeasures = searchCustomMeasures(dbSession, component, searchOptions);
        int nbCustomMeasures = countTotalOfCustomMeasures(dbSession, component);
        Map<String, UserDto> usersByLogin = usersByLogin(dbSession, customMeasures);
        Map<Integer, MetricDto> metricsById = metricsById(dbSession, customMeasures);
        writeResponse(response, customMeasures, nbCustomMeasures, component, metricsById, usersByLogin, lastAnalysisDateMs, searchOptions, fieldsToReturn);
    }
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto)

Aggregations

CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)38 Test (org.junit.Test)30 MetricDto (org.sonar.db.metric.MetricDto)26 CustomMeasureTesting.newCustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto)12 ComponentDto (org.sonar.db.component.ComponentDto)11 MetricImpl (org.sonar.server.computation.task.projectanalysis.metric.MetricImpl)7 DbSession (org.sonar.db.DbSession)4 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)4 OrganizationDto (org.sonar.db.organization.OrganizationDto)4 UserDto (org.sonar.db.user.UserDto)3 WsTester (org.sonar.server.ws.WsTester)3 JsonWriter (org.sonar.api.utils.text.JsonWriter)2 Measure (org.sonar.server.computation.task.projectanalysis.measure.Measure)1 Metric (org.sonar.server.computation.task.projectanalysis.metric.Metric)1 SearchOptions (org.sonar.server.es.SearchOptions)1