public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) { checkNotNull(project.getId(), "The project need to be persisted before creating this technical project."); return newChildComponent(uuid, view, view) .setDbKey(view.getDbKey() + project.getDbKey()) .setName(project.name()) .setLongName(project.longName()) .setCopyComponentUuid(project.uuid()) .setScope(Scopes.FILE) .setQualifier(Qualifiers.PROJECT) .setPath(null) .setLanguage(null); }
public static ComponentDoc toDocument(ComponentDto component) { return new ComponentDoc() .setId(component.uuid()) .setName(component.name()) .setKey(component.getDbKey()) .setProjectUuid(component.projectUuid()) .setOrganization(component.getOrganizationUuid()) .setLanguage(component.language()) .setQualifier(component.qualifier()); } }
private static boolean isMainProject(ComponentDto p) { return Scopes.PROJECT.equals(p.scope()) && Qualifiers.PROJECT.equals(p.qualifier()) && p.getMainBranchProjectUuid() == null; }
/** * @throws IllegalArgumentException if specified {@link ComponentDto} is not a project. */ private static void checkScopeAndQualifier(ComponentDto projectDto) { String scope = projectDto.scope(); String qualifier = projectDto.qualifier(); checkArgument( scope.equals(Scopes.PROJECT) && qualifier.equals(Qualifiers.PROJECT), "Component %s must be a project (scope=%s, qualifier=%s)", projectDto.uuid(), scope, qualifier); }
private static ProjectMeasuresDoc newDoc(ComponentDto project) { return new ProjectMeasuresDoc() .setOrganizationUuid(project.getOrganizationUuid()) .setId(project.uuid()) .setKey(project.getDbKey()) .setName(project.name()); }
private ComponentDto insertComponent(String key, String uuid) { ComponentDto componentDto = new ComponentDto() .setOrganizationUuid("org1") .setDbKey(key) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) .setProjectUuid(uuid); dbClient.componentDao().insert(db.getSession(), componentDto); return componentDto; }
public void updateKey(DbSession dbSession, ComponentDto projectOrModule, String newKey) { userSession.checkComponentPermission(UserRole.ADMIN, projectOrModule); checkIsProjectOrModule(projectOrModule); checkProjectOrModuleKeyFormat(newKey); dbClient.componentKeyUpdaterDao().updateKey(dbSession, projectOrModule.uuid(), newKey); projectIndexers.commitAndIndex(dbSession, singletonList(projectOrModule), ProjectIndexer.Cause.PROJECT_KEY_UPDATE); if (isMainProject(projectOrModule)) { Project newProject = new Project(projectOrModule.uuid(), newKey, projectOrModule.name(), projectOrModule.description(), projectOrModule.getTags()); projectLifeCycleListeners.onProjectsRekeyed(singleton(new RekeyedProject(newProject, projectOrModule.getDbKey()))); } }
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 static List<Component> writeProjects(List<ComponentDto> projects, Set<String> desiredFields) { return projects.stream().map(project -> { Component.Builder compBuilder = Component.newBuilder().setUuid(project.uuid()); writeIfNeeded("key", project.getDbKey(), compBuilder::setKey, desiredFields); writeIfNeeded("name", project.name(), compBuilder::setName, desiredFields); writeIfNeeded("creationDate", project.getCreatedAt(), compBuilder::setCreationDate, desiredFields); writeIfNeeded("visibility", project.isPrivate() ? PRIVATE.getLabel() : PUBLIC.getLabel(), compBuilder::setVisibility, desiredFields); return compBuilder.build(); }).collect(toList()); }
@Test public void return_private_project_without_any_permission_when_no_permission_in_DB() { List<IndexPermissions> dtos = underTest.selectByUuids(dbClient, dbSession, singletonList(privateProject1.uuid())); // no permissions Assertions.assertThat(dtos).hasSize(1); IndexPermissions dto = dtos.get(0); assertThat(dto.getGroupIds()).isEmpty(); assertThat(dto.getUserIds()).isEmpty(); assertThat(dto.isAllowAnyone()).isFalse(); assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.uuid()); assertThat(dto.getQualifier()).isEqualTo(privateProject1.qualifier()); }
private ComponentDto createForProjectView(Component projectView, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto res = createBase(projectView); res.setScope(Scopes.FILE); res.setQualifier(Qualifiers.PROJECT); res.setName(projectView.getName()); res.setLongName(res.name()); res.setCopyComponentUuid(projectView.getProjectViewAttributes().getProjectUuid()); setRootAndParentModule(res, path); return res; }
@Test public void submit_a_report_on_existing_project_with_project_scan_permission() { ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization()); userSession.addProjectPermission(SCAN_EXECUTION, project); mockSuccessfulPrepareSubmitCall(); underTest.submit(defaultOrganizationKey, project.getDbKey(), null, project.name(), emptyMap(), IOUtils.toInputStream("{binary}")); verify(queue).submit(any(CeTaskSubmit.class)); }
private static CreateWsResponse toCreateResponse(ComponentDto componentDto) { return CreateWsResponse.newBuilder() .setProject(CreateWsResponse.Project.newBuilder() .setKey(componentDto.getDbKey()) .setName(componentDto.name()) .setQualifier(componentDto.qualifier()) .setVisibility(Visibility.getLabel(componentDto.isPrivate()))) .build(); }
private static BranchSupport.ComponentKey createComponentKeyOfBranch(ComponentDto branch) { BranchSupport.ComponentKey mainComponentKey = mockComponentKey(branch.getKey(), branch.getKey()); when(mainComponentKey.getMainBranchComponentKey()).thenReturn(mainComponentKey); BranchSupport.ComponentKey componentKey = mockComponentKey(branch.getKey(), branch.getDbKey()); when(componentKey.getBranch()).thenReturn(Optional.ofNullable(branch).map(b -> new BranchSupport.Branch(b.name(), BranchType.LONG))); when(componentKey.getMainBranchComponentKey()).thenReturn(mainComponentKey); return componentKey; }
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()); }
protected void assertResultOrder(String query, String... resultsInOrder) { ComponentDto project = indexProject("key-1", "Quality Product"); List<ComponentDto> files = Arrays.stream(resultsInOrder) .map(r -> ComponentTesting.newFileDto(project).setName(r)) .peek(f -> f.setUuid(f.uuid() + "_" + f.name().replaceAll("[^a-zA-Z0-9]", ""))) .collect(Collectors.toList()); // index them, but not in the expected order files.stream() .sorted(Comparator.comparing(ComponentDto::uuid).reversed()) .forEach(this::index); assertExactResults(query, files.toArray(new ComponentDto[0])); }
private ComponentDto setUpProjectWithBranch() { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto branch = newProjectBranch(project, newBranchDto(project).setKey(BRANCH_NAME)); ComponentDto file = newFileDto(branch); treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getDbKey()).setPublicKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build()); return branch; }