Search in sources :

Example 1 with ComponentQuery

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

the class ActivityAction method loadComponentUuids.

@CheckForNull
private List<String> loadComponentUuids(DbSession dbSession, ActivityWsRequest request) {
    String componentUuid = request.getComponentId();
    String componentQuery = request.getQuery();
    if (componentUuid != null) {
        return singletonList(componentUuid);
    }
    if (componentQuery != null) {
        ComponentQuery componentDtoQuery = ComponentQuery.builder().setNameOrKeyQuery(componentQuery).setQualifiers(POSSIBLE_QUALIFIERS.toArray(new String[0])).build();
        List<ComponentDto> componentDtos = dbClient.componentDao().selectByQuery(dbSession, componentDtoQuery, 0, CeTaskQuery.MAX_COMPONENT_UUIDS);
        return Lists.transform(componentDtos, ComponentDto::uuid);
    }
    return null;
}
Also used : ComponentQuery(org.sonar.db.component.ComponentQuery) ComponentDto(org.sonar.db.component.ComponentDto) StringUtils.defaultString(org.apache.commons.lang.StringUtils.defaultString) CheckForNull(javax.annotation.CheckForNull)

Example 2 with ComponentQuery

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

the class SearchAction method doHandle.

private SearchWsResponse doHandle(SearchWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentQuery query = buildQuery(request);
        OrganizationDto organization = getOrganization(dbSession, request);
        Paging paging = buildPaging(dbSession, request, organization, query);
        List<ComponentDto> components = searchComponents(dbSession, organization, query, paging);
        return buildResponse(components, organization, paging);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentQuery(org.sonar.db.component.ComponentQuery) Paging(org.sonar.api.utils.Paging) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 3 with ComponentQuery

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

the class BulkApplyTemplateAction method doHandle.

private void doHandle(BulkApplyTemplateWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        PermissionTemplateDto template = wsSupport.findTemplate(dbSession, newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
        checkGlobalAdmin(userSession, template.getOrganizationUuid());
        ComponentQuery componentQuery = ComponentQuery.builder().setNameOrKeyQuery(request.getQuery()).setQualifiers(qualifiers(request.getQualifier())).build();
        List<ComponentDto> projects = dbClient.componentDao().selectByQuery(dbSession, template.getOrganizationUuid(), componentQuery, 0, Integer.MAX_VALUE);
        permissionTemplateService.apply(dbSession, template, projects);
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) ComponentQuery(org.sonar.db.component.ComponentQuery) ComponentDto(org.sonar.db.component.ComponentDto)

Example 4 with ComponentQuery

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

the class SearchAction method doHandle.

private SearchWsResponse doHandle(SearchWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        OrganizationDto organization = support.getOrganization(dbSession, ofNullable(request.getOrganization()).orElseGet(defaultOrganizationProvider.get()::getKey));
        userSession.checkPermission(OrganizationPermission.ADMINISTER, organization);
        ComponentQuery query = buildQuery(request);
        Paging paging = buildPaging(dbSession, request, organization, query);
        List<ComponentDto> components = dbClient.componentDao().selectByQuery(dbSession, organization.getUuid(), query, paging.offset(), paging.pageSize());
        return buildResponse(components, organization, paging);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentQuery(org.sonar.db.component.ComponentQuery) Paging(org.sonar.api.utils.Paging) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 5 with ComponentQuery

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

the class SearchMyProjectsDataLoader method searchProjects.

@VisibleForTesting
ProjectsResult searchProjects(DbSession dbSession, SearchMyProjectsRequest request) {
    int userId = requireNonNull(userSession.getUserId(), "Current user must be authenticated");
    List<Long> componentIds = dbClient.roleDao().selectComponentIdsByPermissionAndUserId(dbSession, UserRole.ADMIN, userId);
    ComponentQuery dbQuery = ComponentQuery.builder().setQualifiers(Qualifiers.PROJECT).setComponentIds(ImmutableSet.copyOf(componentIds)).build();
    return new ProjectsResult(dbClient.componentDao().selectByQuery(dbSession, dbQuery, offset(request.getPage(), request.getPageSize()), request.getPageSize()), dbClient.componentDao().countByQuery(dbSession, dbQuery));
}
Also used : ComponentQuery(org.sonar.db.component.ComponentQuery) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ComponentQuery (org.sonar.db.component.ComponentQuery)5 ComponentDto (org.sonar.db.component.ComponentDto)4 DbSession (org.sonar.db.DbSession)3 Paging (org.sonar.api.utils.Paging)2 OrganizationDto (org.sonar.db.organization.OrganizationDto)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CheckForNull (javax.annotation.CheckForNull)1 StringUtils.defaultString (org.apache.commons.lang.StringUtils.defaultString)1 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)1