private List<ComponentDto> searchComponents(DbSession dbSession, ComponentTreeQuery componentTreeQuery) { Collection<String> qualifiers = componentTreeQuery.getQualifiers(); if (qualifiers != null && qualifiers.isEmpty()) { return Collections.emptyList(); } return dbClient.componentDao().selectDescendants(dbSession, componentTreeQuery); }
@Test public void select_descendants_returns_empty_list_if_base_component_does_not_exist() { ComponentTreeQuery query = newTreeQuery(PROJECT_UUID).setStrategy(CHILDREN).build(); List<ComponentDto> result = underTest.selectDescendants(dbSession, query); assertThat(result).isEmpty(); }
private void deleteDataOfComponentsWithoutHistoricalData(DbSession dbSession, String rootUuid, Collection<String> scopesWithoutHistoricalData, PurgeCommands purgeCommands) { if (scopesWithoutHistoricalData.isEmpty()) { return; } List<String> analysisUuids = purgeCommands.selectSnapshotUuids( new PurgeSnapshotQuery() .setComponentUuid(rootUuid) .setIslast(false) .setNotPurged(true)); List<String> componentWithoutHistoricalDataUuids = componentDao .selectDescendants( dbSession, ComponentTreeQuery.builder() .setBaseUuid(rootUuid) .setScopes(scopesWithoutHistoricalData) .setStrategy(Strategy.LEAVES) .build()) .stream().map(ComponentDto::uuid) .collect(MoreCollectors.toList()); purgeCommands.deleteComponentMeasures(analysisUuids, componentWithoutHistoricalDataUuids); }
private TreeWsResponse doHandle(Request treeRequest) { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto baseComponent = loadComponent(dbSession, treeRequest); checkPermissions(baseComponent); OrganizationDto organizationDto = componentFinder.getOrganization(dbSession, baseComponent); ComponentTreeQuery query = toComponentTreeQuery(treeRequest, baseComponent); List<ComponentDto> components = dbClient.componentDao().selectDescendants(dbSession, query); int total = components.size(); components = sortComponents(components, treeRequest); components = paginateComponents(components, treeRequest); Map<String, ComponentDto> referenceComponentsByUuid = searchReferenceComponentsByUuid(dbSession, components); return buildResponse(baseComponent, organizationDto, components, referenceComponentsByUuid, Paging.forPageIndex(treeRequest.getPage()).withPageSize(treeRequest.getPageSize()).andTotal(total)); } }
List<ComponentDto> children = underTest.selectDescendants(dbSession, query); assertThat(children).extracting("uuid").containsOnly(FILE_1_UUID, MODULE_UUID); children = underTest.selectDescendants(dbSession, query); assertThat(children).extracting("uuid").containsOnly(MODULE_UUID); assertThat(underTest.selectDescendants(dbSession, query)).extracting("uuid").containsOnly(FILE_2_UUID, FILE_3_UUID); assertThat(underTest.selectDescendants(dbSession, query)).isEmpty(); assertThat(underTest.selectDescendants(dbSession, query)).extracting("uuid").containsOnly(FILE_1_UUID); assertThat(underTest.selectDescendants(dbSession, query)).extracting("uuid").containsOnly(FILE_1_UUID); assertThat(underTest.selectDescendants(dbSession, query)).extracting("uuid").containsOnly(FILE_1_UUID); assertThat(underTest.selectDescendants(dbSession, query)).isEmpty(); assertThat(underTest.selectDescendants(dbSession, query)).extracting("uuid").containsOnly(FILE_2_UUID); assertThat(underTest.selectDescendants(dbSession, query)).isEmpty(); assertThat(underTest.selectDescendants(dbSession, query)).isEmpty(); assertThat(underTest.selectDescendants(dbSession, query)).isEmpty(); assertThat(underTest.selectDescendants(dbSession, query)) .extracting(ComponentDto::uuid) .containsExactlyInAnyOrder(fileInProject.uuid());
@Test public void select_descendants_with_leaves_strategy() { ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID); db.components().insertProjectAndSnapshot(project); db.components().insertComponent(newModuleDto("module-1-uuid", project)); db.components().insertComponent(newFileDto(project, null, "file-1-uuid")); db.components().insertComponent(newFileDto(project, null, "file-2-uuid")); db.commit(); ComponentTreeQuery query = newTreeQuery(PROJECT_UUID).setStrategy(LEAVES).build(); List<ComponentDto> result = underTest.selectDescendants(dbSession, query); assertThat(result).extracting("uuid").containsOnly("file-1-uuid", "file-2-uuid", "module-1-uuid"); }
@Test public void select_descendants_of_a_view_and_filter_by_name() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto view = newView(organizationDto, A_VIEW_UUID); db.components().insertViewAndSnapshot(view); // one subview ComponentDto subView = newSubView(view, "subview-uuid", "subview-key").setName("subview name"); db.components().insertComponent(subView); // one project and its copy linked to the view ComponentDto project = newPrivateProjectDto(organizationDto, PROJECT_UUID).setName("project name"); db.components().insertProjectAndSnapshot(project); db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view)); ComponentTreeQuery dbQuery = newTreeQuery(A_VIEW_UUID).setNameOrKeyQuery("name").setStrategy(CHILDREN).build(); List<ComponentDto> components = underTest.selectDescendants(dbSession, dbQuery); assertThat(components).extracting("uuid").containsOnly("project-copy-uuid", "subview-uuid"); assertThat(components).extracting("organizationUuid").containsOnly(organizationDto.getUuid()); }
private List<ComponentDto> searchComponents(DbSession dbSession, ComponentTreeQuery componentTreeQuery) { Collection<String> qualifiers = componentTreeQuery.getQualifiers(); if (qualifiers != null && qualifiers.isEmpty()) { return Collections.emptyList(); } return dbClient.componentDao().selectDescendants(dbSession, componentTreeQuery); }
private void deleteDataOfComponentsWithoutHistoricalData(DbSession dbSession, String rootUuid, String[] scopesWithoutHistoricalData, PurgeCommands purgeCommands) { if (scopesWithoutHistoricalData.length == 0) { return; } List<String> analysisUuids = purgeCommands.selectSnapshotUuids( new PurgeSnapshotQuery() .setComponentUuid(rootUuid) .setIslast(false) .setNotPurged(true)); List<String> componentWithoutHistoricalDataUuids = componentDao .selectDescendants( dbSession, ComponentTreeQuery.builder() .setBaseUuid(rootUuid) .setQualifiers(Arrays.asList(scopesWithoutHistoricalData)) .setStrategy(Strategy.LEAVES) .build()) .stream().map(ComponentDto::uuid) .collect(Collectors.toList()); purgeCommands.deleteComponentMeasures(analysisUuids, componentWithoutHistoricalDataUuids); }
private TreeWsResponse doHandle(Request treeRequest) { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto baseComponent = loadComponent(dbSession, treeRequest); checkPermissions(baseComponent); OrganizationDto organizationDto = componentFinder.getOrganization(dbSession, baseComponent); ComponentTreeQuery query = toComponentTreeQuery(treeRequest, baseComponent); List<ComponentDto> components = dbClient.componentDao().selectDescendants(dbSession, query); int total = components.size(); components = sortComponents(components, treeRequest); components = paginateComponents(components, treeRequest); Map<String, ComponentDto> referenceComponentsByUuid = searchReferenceComponentsByUuid(dbSession, components); return buildResponse(baseComponent, organizationDto, components, referenceComponentsByUuid, Paging.forPageIndex(treeRequest.getPage()).withPageSize(treeRequest.getPageSize()).andTotal(total)); } }