Search in sources :

Example 11 with MetricDto

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

the class ComponentAction method doHandle.

private ComponentWsResponse doHandle(ComponentWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.getComponentId(), request.getComponentKey(), COMPONENT_ID_AND_KEY);
        Long developerId = searchDeveloperId(dbSession, request);
        Optional<ComponentDto> refComponent = getReferenceComponent(dbSession, component);
        checkPermissions(component);
        SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.projectUuid()).orElse(null);
        List<MetricDto> metrics = searchMetrics(dbSession, request);
        List<WsMeasures.Period> periods = snapshotToWsPeriods(analysis);
        List<MeasureDto> measures = searchMeasures(dbSession, component, analysis, metrics, developerId);
        return buildResponse(request, component, refComponent, measures, metrics, periods);
    }
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto)

Example 12 with MetricDto

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

the class ComponentDtoToWsComponent method componentDtoToWsComponent.

static Component.Builder componentDtoToWsComponent(ComponentDto component, Map<MetricDto, MeasureDto> measuresByMetric, Map<String, ComponentDto> referenceComponentsByUuid) {
    Component.Builder wsComponent = componentDtoToWsComponent(component);
    ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyResourceUuid());
    if (referenceComponent != null) {
        wsComponent.setRefId(referenceComponent.uuid());
        wsComponent.setRefKey(referenceComponent.key());
    }
    for (Map.Entry<MetricDto, MeasureDto> entry : measuresByMetric.entrySet()) {
        wsComponent.addMeasures(measureDtoToWsMeasure(entry.getKey(), entry.getValue()));
    }
    return wsComponent;
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonarqube.ws.WsMeasures.Component) Map(java.util.Map)

Example 13 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 {
    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 14 with MetricDto

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

the class MetricsAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto project = componentFinder.getByUuidOrKey(dbSession, request.param(CreateAction.PARAM_PROJECT_ID), request.param(CreateAction.PARAM_PROJECT_KEY), PROJECT_ID_AND_KEY);
        checkPermissions(userSession, project);
        List<MetricDto> metrics = searchMetrics(dbSession, project);
        writeResponse(response.newJsonWriter(), metrics);
    }
}
Also used : DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto)

Example 15 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 {
    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

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