Search in sources :

Example 1 with ComponentTreeQuery

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

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

the class FileMoveDetectionStepTest method execute_retrieves_only_file_and_unit_tests_from_last_snapshot.

@Test
public void execute_retrieves_only_file_and_unit_tests_from_last_snapshot() {
    analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
    ArgumentCaptor<ComponentTreeQuery> captor = ArgumentCaptor.forClass(ComponentTreeQuery.class);
    when(componentDao.selectDescendants(eq(dbSession), captor.capture())).thenReturn(Collections.emptyList());
    underTest.execute();
    ComponentTreeQuery query = captor.getValue();
    assertThat(query.getBaseUuid()).isEqualTo(PROJECT.getUuid());
    assertThat(query.getQualifiers()).containsOnly(FILE, UNIT_TEST_FILE);
}
Also used : ComponentTreeQuery(org.sonar.db.component.ComponentTreeQuery) Test(org.junit.Test)

Example 3 with ComponentTreeQuery

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

the class TreeAction method doHandle.

private TreeWsResponse doHandle(TreeWsRequest treeWsRequest) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto baseComponent = componentFinder.getByUuidOrKey(dbSession, treeWsRequest.getBaseComponentId(), treeWsRequest.getBaseComponentKey(), COMPONENT_ID_AND_COMPONENT);
        checkPermissions(baseComponent);
        OrganizationDto organizationDto = componentFinder.getOrganization(dbSession, baseComponent);
        ComponentTreeQuery query = toComponentTreeQuery(treeWsRequest, baseComponent);
        List<ComponentDto> components = dbClient.componentDao().selectDescendants(dbSession, query);
        int total = components.size();
        components = sortComponents(components, treeWsRequest);
        components = paginateComponents(components, treeWsRequest);
        Map<String, ComponentDto> referenceComponentsByUuid = searchReferenceComponentsByUuid(dbSession, components);
        return buildResponse(baseComponent, organizationDto, components, referenceComponentsByUuid, Paging.forPageIndex(treeWsRequest.getPage()).withPageSize(treeWsRequest.getPageSize()).andTotal(total));
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentTreeQuery(org.sonar.db.component.ComponentTreeQuery) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Aggregations

ComponentTreeQuery (org.sonar.db.component.ComponentTreeQuery)3 DbSession (org.sonar.db.DbSession)2 ComponentDto (org.sonar.db.component.ComponentDto)2 Test (org.junit.Test)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1 MeasureDto (org.sonar.db.measure.MeasureDto)1 MetricDto (org.sonar.db.metric.MetricDto)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1