private ComponentDto getParentProject(String rootUuid, Map<String, ComponentDto> subProjectsByUuid, DbSession session) { ComponentDto project = subProjectsByUuid.get(rootUuid); if (project == null) { Optional<ComponentDto> projectOptional = componentDao.selectByUuid(session, rootUuid); if (projectOptional.isPresent()) { project = projectOptional.get(); subProjectsByUuid.put(project.uuid(), project); } } return project; }
@Override public Integer apply(@Nonnull ComponentDto input) { ComponentTreeData.Measure measure = measuresByComponentUuidAndMetric.get(input.uuid(), metric); if (measure == null || measure.getData() == null) { return null; } return Metric.Level.names().indexOf(measure.getData()); } }
private ComponentDto checkIsProject(ComponentDto component) { Set<String> rootQualifiers = getRootQualifiers(resourceTypes); checkRequest(component.scope().equals(Scopes.PROJECT) && rootQualifiers.contains(component.qualifier()), format( "Component '%s' (id: %s) must be a project%s.", component.getDbKey(), component.uuid(), rootQualifiers.contains(Qualifiers.VIEW) ? " or a view" : "")); return component; }
private void loadProjects(Collector collector, DbSession dbSession, SearchResponseData result) { Collection<ComponentDto> loadedComponents = result.getComponents(); for (ComponentDto component : loadedComponents) { collector.addProjectUuid(component.projectUuid()); } Set<String> loadedProjectUuids = loadedComponents.stream().filter(cpt -> cpt.uuid().equals(cpt.projectUuid())).map(ComponentDto::uuid).collect(MoreCollectors.toSet()); Set<String> projectUuidsToLoad = copyOf(difference(collector.getProjectUuids(), loadedProjectUuids)); if (!projectUuidsToLoad.isEmpty()) { List<ComponentDto> projects = dbClient.componentDao().selectByUuids(dbSession, collector.getProjectUuids()); result.addComponents(projects); } }
public void delete(DbSession dbSession, ComponentDto project) { checkArgument(!hasNotProjectScope(project) && !isNotDeletable(project) && project.getMainBranchProjectUuid() == null, "Only projects can be deleted"); dbClient.purgeDao().deleteProject(dbSession, project.uuid()); dbClient.userDao().cleanHomepage(dbSession, project); projectIndexers.commitAndIndex(dbSession, singletonList(project), PROJECT_DELETION); }
private static void verifyFileMoveRowDto(RecordingResultHandler resultHander, ComponentAndSource componentAndSource) { FileMoveRowDto dto = resultHander.getById(componentAndSource.component.getId()).get(); assertThat(dto.getKey()).isEqualTo(componentAndSource.component.getDbKey()); assertThat(dto.getUuid()).isEqualTo(componentAndSource.component.uuid()); assertThat(dto.getPath()).isEqualTo(componentAndSource.component.path()); assertThat(dto.getLineCount()).isEqualTo(componentAndSource.source.getLineCount()); }
@Test public void selectRootAndModulesOrSubviewsByProjectUuid_returns_modules_with_specified_project_uuid_and_project() { ComponentDto project = randomPublicOrPrivateProject(); ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)); ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(project)); ComponentDto module3 = db.components().insertComponent(ComponentTesting.newModuleDto(project)); assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(project.uuid())) .extracting(IdUuidPair::getUuid) .containsOnly(project.uuid(), module1.uuid(), module2.uuid(), module3.uuid()); }
private void assertThatRatingMeasureHasLeakValue(ComponentDto component, Rating expectedValue) { LiveMeasureDto measure = db.getDbClient().liveMeasureDao().selectMeasure(db.getSession(), component.uuid(), ratingMetric.getKey()).get(); assertThat(measure.getComponentUuid()).isEqualTo(component.uuid()); assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid()); assertThat(measure.getMetricId()).isEqualTo(ratingMetric.getId()); assertThat(measure.getVariation()).isEqualTo((double) expectedValue.getIndex()); }
private ComponentDto createAndIndexPublicProject(OrganizationDto org) { ComponentDto project = db.components().insertPublicProject(org); fooIndexer.indexOnAnalysis(project.uuid()); return project; }
@Test public void do_nothing_if_no_webhooks() { ComponentDto componentDto = componentDbTester.insertPrivateProject().setOrganizationUuid(defaultOrganizationProvider.get().getUuid()); underTest.sendProjectAnalysisUpdate(new WebHooks.Analysis(componentDto.uuid(), "1", "#1"), () -> mock); assertThat(caller.countSent()).isEqualTo(0); assertThat(logTester.logs(DEBUG)).isEmpty(); verifyZeroInteractions(deliveryStorage); }
@Test public void fail_to_getByUuid_on_branch() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(format("Component id '%s' not found", branch.uuid())); underTest.getByUuid(dbSession, branch.uuid()); }
@Test public void fail_when_pull_request_branch_provided() { ComponentDto project = db.components().insertMainBranch(); ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Either branch or pull request can be provided, not both"); assertThat(underTest.getByKeyAndOptionalBranchOrPullRequest(dbSession, project.getKey(), "pr-123", "pr-123").uuid()).isEqualTo(pullRequest.uuid()); }
@Test public void fail_if_empty_metric() { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Metric keys must be provided"); call(singletonList(project.uuid()), emptyList()); }
@Test public void non_main_branches_are_not_indexed_during_analysis() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo")); underTest.indexOnAnalysis(branch.uuid()); assertThat(es.countDocuments(INDEX_TYPE_PROJECT_MEASURES)).isEqualTo(0); }
private void failIfComponentIsNotAProjectOrView(ComponentDto file) { loginAsAdmin(db.getDefaultOrganization()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Component '" + file.getDbKey() + "' (id: " + file.uuid() + ") must be a project or a view."); newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) .setParam(PARAM_PROJECT_ID, file.uuid()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); }
private long insertCustomMeasure(ComponentDto component) { CustomMeasureDto dto = newCustomMeasureDto().setComponentUuid(component.uuid()); dbClient.customMeasureDao().insert(dbSession, dto); dbSession.commit(); return dto.getId(); }
@Test public void fail_to_show_source_if_no_source_found() throws Exception { ComponentDto file = insertFile(privateProject); setUserWithValidPermission(file); expectedException.expect(NotFoundException.class); wsTester.newGetRequest("api/sources", "lines").setParam("uuid", file.uuid()).execute(); }
@Before public void prepare() { rule = dbTester.rules().insert(); ruleRepositoryRule.add(rule.getKey()); rootProjectDto = dbTester.components().insertMainBranch(); ReportComponent rootProject = ReportComponent.builder(Component.Type.FILE, 1) .setKey(rootProjectDto.getDbKey()) .setUuid(rootProjectDto.uuid()).build(); reportModulesPath = mock(ReportModulesPath.class); underTest = new ProjectTrackerBaseLazyInput(analysisMetadataHolder, mock(ComponentsWithUnprocessedIssues.class), dbClient, new IssueFieldsSetter(), issuesLoader, reportModulesPath, rootProject); }
@Test public void use_deprecated_component_id_parameter() { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project); userSession.addProjectPermission(USER, project); MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT")); ComponentWsResponse response = ws.newRequest() .setParam("componentId", project.uuid()) .setParam(PARAM_METRIC_KEYS, metric.getKey()) .executeProtobuf(ComponentWsResponse.class); assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); }