/** * Index a root view : it will load projects on each sub views and index it. * Used by the compute engine to reindex a root view. * <p/> * The views lookup cache will be cleared */ public void index(String rootViewUuid) { try (DbSession dbSession = dbClient.openSession(false)) { Map<String, String> viewAndProjectViewUuidMap = newHashMap(); for (ComponentDto viewOrSubView : dbClient.componentDao().selectEnabledDescendantModules(dbSession, rootViewUuid)) { viewAndProjectViewUuidMap.put(viewOrSubView.uuid(), viewOrSubView.projectUuid()); } index(dbSession, viewAndProjectViewUuidMap, true, Size.REGULAR); } }
: componentFinder.getByKeyAndOptionalBranchOrPullRequest(session, projectKey, branch, pullRequest); List<ComponentDto> modulesTree = dbClient.componentDao().selectEnabledDescendantModules(session, branchOrMainModule.uuid());
@Test public void select_enabled_modules_tree() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false)); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false)); ComponentDto subModule = db.components().insertComponent(newModuleDto(module)); ComponentDto removedSubModule = db.components().insertComponent(newModuleDto(module).setEnabled(false)); ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src")); ComponentDto removedDirectory = db.components().insertComponent(newDirectory(subModule, "src2").setEnabled(false)); ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory)); ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false)); // From root project assertThat(underTest.selectEnabledDescendantModules(dbSession, project.uuid())) .extracting(ComponentDto::uuid) .containsExactlyInAnyOrder(project.uuid(), module.uuid(), subModule.uuid()) .doesNotContain(removedModule.uuid(), removedSubModule.uuid()); // From module assertThat(underTest.selectEnabledDescendantModules(dbSession, module.uuid())) .extracting(ComponentDto::uuid) .containsExactlyInAnyOrder(module.uuid(), subModule.uuid()) .doesNotContain(removedModule.uuid(), removedModule.uuid()); // From sub module assertThat(underTest.selectEnabledDescendantModules(dbSession, subModule.uuid())) .extracting(ComponentDto::uuid) .containsExactlyInAnyOrder(subModule.uuid()); // Folder assertThat(underTest.selectEnabledDescendantModules(dbSession, directory.uuid())).isEmpty(); assertThat(underTest.selectEnabledDescendantModules(dbSession, "unknown")).isEmpty(); }
/** * Index a root view : it will load projects on each sub views and index it. * Used by the compute engine to reindex a root view. * <p/> * The views lookup cache will be cleared */ public void index(String rootViewUuid) { try (DbSession dbSession = dbClient.openSession(false)) { Map<String, String> viewAndProjectViewUuidMap = newHashMap(); for (ComponentDto viewOrSubView : dbClient.componentDao().selectEnabledDescendantModules(dbSession, rootViewUuid)) { viewAndProjectViewUuidMap.put(viewOrSubView.uuid(), viewOrSubView.projectUuid()); } index(dbSession, viewAndProjectViewUuidMap, true, Size.REGULAR); } }
public ProjectRepositories load(ProjectDataQuery query) { try (DbSession session = dbClient.openSession(false)) { ProjectRepositories data = new ProjectRepositories(); String moduleKey = query.getModuleKey(); String branch = query.getBranch(); String pullRequest = query.getPullRequest(); ComponentDto mainModule = componentFinder.getByKey(session, moduleKey); checkRequest(isProjectOrModule(mainModule), "Key '%s' belongs to a component which is not a Project", moduleKey); boolean hasScanPerm = userSession.hasComponentPermission(SCAN_EXECUTION, mainModule) || userSession.hasPermission(OrganizationPermission.SCAN, mainModule.getOrganizationUuid()); boolean hasBrowsePerm = userSession.hasComponentPermission(USER, mainModule); checkPermission(query.isIssuesMode(), hasScanPerm, hasBrowsePerm); ComponentDto branchOrMainModule = (branch == null && pullRequest == null) ? mainModule : componentFinder.getByKeyAndOptionalBranchOrPullRequest(session, moduleKey, branch, pullRequest); ComponentDto project = getProject(branchOrMainModule, session); if (!project.getKey().equals(branchOrMainModule.getKey())) { addSettings(data, branchOrMainModule.getKey(), getSettingsFromParents(branchOrMainModule, hasScanPerm, session)); } List<ComponentDto> modulesTree = dbClient.componentDao().selectEnabledDescendantModules(session, branchOrMainModule.uuid()); List<PropertyDto> modulesTreeSettings = dbClient.propertiesDao().selectEnabledDescendantModuleProperties(mainModule.uuid(), session); TreeModuleSettings treeModuleSettings = new TreeModuleSettings(session, modulesTree, modulesTreeSettings); addSettingsToChildrenModules(data, moduleKey, Maps.newHashMap(), treeModuleSettings, hasScanPerm); List<FilePathWithHashDto> files = searchFilesWithHashAndRevision(session, branchOrMainModule); addFileData(data, modulesTree, files); // FIXME need real value but actually only used to know if there is a previous analysis in local issue tracking mode so any value is // ok data.setLastAnalysisDate(new Date()); return data; } }