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();
}
}
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);
}
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));
}
}
Aggregations