Search in sources :

Example 76 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class ComponentTreeDataLoader method load.

ComponentTreeData load(ComponentTreeWsRequest wsRequest) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto baseComponent = componentFinder.getByUuidOrKey(dbSession, wsRequest.getBaseComponentId(), wsRequest.getBaseComponentKey(), BASE_COMPONENT_ID_AND_KEY);
        checkPermissions(baseComponent);
        Optional<SnapshotDto> baseSnapshot = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, baseComponent.projectUuid());
        if (!baseSnapshot.isPresent()) {
            return ComponentTreeData.builder().setBaseComponent(baseComponent).build();
        }
        Long developerId = searchDeveloperId(dbSession, wsRequest);
        ComponentTreeQuery componentTreeQuery = toComponentTreeQuery(wsRequest, baseComponent);
        List<ComponentDto> components = searchComponents(dbSession, componentTreeQuery);
        List<MetricDto> metrics = searchMetrics(dbSession, wsRequest);
        Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric = searchMeasuresByComponentUuidAndMetric(dbSession, baseComponent, componentTreeQuery, components, metrics, developerId);
        components = filterComponents(components, measuresByComponentUuidAndMetric, metrics, wsRequest);
        components = sortComponents(components, wsRequest, metrics, measuresByComponentUuidAndMetric);
        int componentCount = components.size();
        components = paginateComponents(components, wsRequest);
        return ComponentTreeData.builder().setBaseComponent(baseComponent).setComponentsFromDb(components).setComponentCount(componentCount).setMeasuresByComponentUuidAndMetric(measuresByComponentUuidAndMetric).setMetrics(metrics).setPeriods(snapshotToWsPeriods(baseSnapshot.get())).setReferenceComponentsByUuid(searchReferenceComponentsById(dbSession, components)).build();
    }
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) MeasureDto(org.sonar.db.measure.MeasureDto) DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) ComponentTreeQuery(org.sonar.db.component.ComponentTreeQuery)

Example 77 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class SearchHistoryAction method searchComponent.

private ComponentDto searchComponent(SearchHistoryRequest request, DbSession dbSession) {
    ComponentDto component = componentFinder.getByKey(dbSession, request.getComponent());
    userSession.checkComponentPermission(UserRole.USER, component);
    return component;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto)

Example 78 with ComponentDto

use of org.sonar.db.component.ComponentDto 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 79 with ComponentDto

use of org.sonar.db.component.ComponentDto 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 80 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class ListAction method populateProjectFields.

private static Notification.Builder populateProjectFields(Notification.Builder notification, Long componentId, Map<String, OrganizationDto> organizationsByUuid, Map<Long, ComponentDto> projectsById) {
    ComponentDto project = projectsById.get(componentId);
    String organizationUuid = project.getOrganizationUuid();
    OrganizationDto organizationDto = organizationsByUuid.get(organizationUuid);
    checkArgument(organizationDto != null, "No organization for uuid '%s'", organizationUuid);
    return notification.setOrganization(organizationDto.getKey()).setProject(project.getKey()).setProjectName(project.name());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Aggregations

ComponentDto (org.sonar.db.component.ComponentDto)836 Test (org.junit.Test)661 OrganizationDto (org.sonar.db.organization.OrganizationDto)151 SnapshotDto (org.sonar.db.component.SnapshotDto)94 DbSession (org.sonar.db.DbSession)70 SearchOptions (org.sonar.server.es.SearchOptions)62 MetricDto (org.sonar.db.metric.MetricDto)49 IssueDto (org.sonar.db.issue.IssueDto)48 RuleDto (org.sonar.db.rule.RuleDto)47 GroupDto (org.sonar.db.user.GroupDto)39 UserDto (org.sonar.db.user.UserDto)38 WsTester (org.sonar.server.ws.WsTester)33 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)25 PropertyDto (org.sonar.db.property.PropertyDto)23 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)21 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)18 Date (java.util.Date)16 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)14 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)13