Search in sources :

Example 41 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class GroupPermissionDaoTest method delete_global_permission_from_group.

@Test
public void delete_global_permission_from_group() {
    OrganizationDto org = db.organizations().insert();
    GroupDto group1 = db.users().insertGroup(org);
    ComponentDto project1 = db.components().insertProject(org);
    db.users().insertPermissionOnAnyone(org, "perm1");
    db.users().insertPermissionOnGroup(group1, "perm2");
    db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
    db.users().insertProjectPermissionOnAnyone("perm4", project1);
    underTest.delete(dbSession, "perm2", group1.getOrganizationUuid(), group1.getId(), null);
    dbSession.commit();
    assertThatNoPermission("perm2");
    assertThat(db.countRowsOfTable("group_roles")).isEqualTo(3);
}
Also used : GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 42 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class GroupPermissionDaoTest method select_groups_by_query_with_project_permissions.

@Test
public void select_groups_by_query_with_project_permissions() {
    GroupDto group1 = db.users().insertGroup();
    GroupDto group2 = db.users().insertGroup();
    GroupDto group3 = db.users().insertGroup();
    ComponentDto project = db.components().insertProject();
    ComponentDto anotherProject = db.components().insertProject();
    db.users().insertProjectPermissionOnGroup(group1, SCAN_EXECUTION, project);
    db.users().insertProjectPermissionOnGroup(group1, PROVISIONING, project);
    db.users().insertProjectPermissionOnAnyone(USER, project);
    db.users().insertProjectPermissionOnGroup(group1, SYSTEM_ADMIN, anotherProject);
    db.users().insertProjectPermissionOnAnyone(SYSTEM_ADMIN, anotherProject);
    db.users().insertProjectPermissionOnGroup(group3, SCAN_EXECUTION, anotherProject);
    db.users().insertPermissionOnGroup(group2, SCAN);
    PermissionQuery.Builder builderOnComponent = PermissionQuery.builder().setComponentUuid(project.uuid());
    assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, builderOnComponent.withAtLeastOnePermission().build())).containsOnlyOnce(group1.getName());
    assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, builderOnComponent.setPermission(SCAN_EXECUTION).build())).containsOnlyOnce(group1.getName());
    assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, builderOnComponent.setPermission(USER).build())).containsOnlyOnce(ANYONE);
}
Also used : GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 43 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class SuggestionsAction method getResultsOfAllQualifiers.

private List<Qualifier> getResultsOfAllQualifiers(String query) {
    ComponentIndexQuery componentIndexQuery = new ComponentIndexQuery(query).setQualifiers(Arrays.asList(QUALIFIERS)).setLimit(NUMBER_OF_RESULTS_PER_QUALIFIER);
    List<ComponentsPerQualifier> componentsPerQualifiers = searchInIndex(componentIndexQuery);
    if (componentsPerQualifiers.isEmpty()) {
        return Collections.emptyList();
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        return componentsPerQualifiers.stream().map(qualifier -> {
            List<String> uuids = qualifier.getComponentUuids();
            List<ComponentDto> componentDtos = dbClient.componentDao().selectByUuids(dbSession, uuids);
            List<ComponentDto> sortedComponentDtos = Ordering.explicit(uuids).onResultOf(ComponentDto::uuid).immutableSortedCopy(componentDtos);
            Map<String, String> organizationKeyByUuids = getOrganizationKeys(dbSession, componentDtos);
            List<Component> results = sortedComponentDtos.stream().map(dto -> dtoToComponent(dto, organizationKeyByUuids)).collect(Collectors.toList());
            return Qualifier.newBuilder().setQ(qualifier.getQualifier()).addAllItems(results).build();
        }).collect(Collectors.toList());
    }
}
Also used : Arrays(java.util.Arrays) Qualifier(org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Qualifier) DbSession(org.sonar.db.DbSession) ACTION_SUGGESTIONS(org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SUGGESTIONS) Request(org.sonar.api.server.ws.Request) WebService(org.sonar.api.server.ws.WebService) ComponentIndexQuery(org.sonar.server.component.index.ComponentIndexQuery) Map(java.util.Map) Response(org.sonar.api.server.ws.Response) OrganizationDto(org.sonar.db.organization.OrganizationDto) SuggestionsWsResponse(org.sonarqube.ws.WsComponents.SuggestionsWsResponse) Resources(com.google.common.io.Resources) Collectors(org.sonar.core.util.stream.Collectors) Component(org.sonarqube.ws.WsComponents.Component) NewAction(org.sonar.api.server.ws.WebService.NewAction) Preconditions.checkState(com.google.common.base.Preconditions.checkState) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Ordering(com.google.common.collect.Ordering) Qualifiers(org.sonar.api.resources.Qualifiers) ComponentIndex(org.sonar.server.component.index.ComponentIndex) ComponentsPerQualifier(org.sonar.server.component.index.ComponentsPerQualifier) Collections(java.util.Collections) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) DbSession(org.sonar.db.DbSession) ComponentsPerQualifier(org.sonar.server.component.index.ComponentsPerQualifier) ComponentDto(org.sonar.db.component.ComponentDto) ComponentIndexQuery(org.sonar.server.component.index.ComponentIndexQuery) List(java.util.List) Map(java.util.Map)

Example 44 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class TreeAction method toWsComponent.

private static WsComponents.Component.Builder toWsComponent(ComponentDto component, OrganizationDto organizationDto, Map<String, ComponentDto> referenceComponentsByUuid) {
    WsComponents.Component.Builder wsComponent = componentDtoToWsComponent(component, organizationDto, Optional.empty());
    ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyResourceUuid());
    if (referenceComponent != null) {
        wsComponent.setRefId(referenceComponent.uuid());
        wsComponent.setRefKey(referenceComponent.key());
    }
    return wsComponent;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) ComponentDtoToWsComponent.componentDtoToWsComponent(org.sonar.server.component.ws.ComponentDtoToWsComponent.componentDtoToWsComponent)

Example 45 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class TreeAction method buildResponse.

private static TreeWsResponse buildResponse(ComponentDto baseComponent, OrganizationDto organizationDto, List<ComponentDto> components, Map<String, ComponentDto> referenceComponentsByUuid, Paging paging) {
    TreeWsResponse.Builder response = TreeWsResponse.newBuilder();
    response.getPagingBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()).setTotal(paging.total()).build();
    response.setBaseComponent(toWsComponent(baseComponent, organizationDto, referenceComponentsByUuid));
    for (ComponentDto dto : components) {
        response.addComponents(toWsComponent(dto, organizationDto, referenceComponentsByUuid));
    }
    return response.build();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TreeWsResponse(org.sonarqube.ws.WsComponents.TreeWsResponse)

Aggregations

ComponentDto (org.sonar.db.component.ComponentDto)836 Test (org.junit.Test)661 OrganizationDto (org.sonar.db.organization.OrganizationDto)151 SnapshotDto (org.sonar.db.component.SnapshotDto)94 DbSession (org.sonar.db.DbSession)70 SearchOptions (org.sonar.server.es.SearchOptions)62 MetricDto (org.sonar.db.metric.MetricDto)49 IssueDto (org.sonar.db.issue.IssueDto)48 RuleDto (org.sonar.db.rule.RuleDto)47 GroupDto (org.sonar.db.user.GroupDto)39 UserDto (org.sonar.db.user.UserDto)38 WsTester (org.sonar.server.ws.WsTester)33 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)25 PropertyDto (org.sonar.db.property.PropertyDto)23 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)21 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)18 Date (java.util.Date)16 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)14 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)13