Search in sources :

Example 91 with ComponentDto

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

the class ApplyTemplateAction method doHandle.

private void doHandle(ApplyTemplateWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        PermissionTemplateDto template = wsSupport.findTemplate(dbSession, newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
        ComponentDto project = wsSupport.getRootComponentOrModule(dbSession, newWsProjectRef(request.getProjectId(), request.getProjectKey()));
        checkGlobalAdmin(userSession, template.getOrganizationUuid());
        permissionTemplateService.apply(dbSession, template, Collections.singletonList(project));
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) ComponentDto(org.sonar.db.component.ComponentDto)

Example 92 with ComponentDto

use of org.sonar.db.component.ComponentDto 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 93 with ComponentDto

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

the class IndexAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<ComponentDto> projects = getAuthorizedComponents(dbSession, searchComponents(dbSession, request));
        JsonWriter json = response.newJsonWriter();
        json.beginArray();
        for (ComponentDto project : projects) {
            addProject(json, project);
        }
        json.endArray();
        json.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 94 with ComponentDto

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

the class ProvisionedAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn();
    SearchOptions options = new SearchOptions().setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE));
    Set<String> desiredFields = desiredFields(request);
    String query = request.param(Param.TEXT_QUERY);
    try (DbSession dbSession = dbClient.openSession(false)) {
        OrganizationDto organization = support.getOrganization(dbSession, request.getParam(PARAM_ORGANIZATION).or(defaultOrganizationProvider.get()::getKey));
        userSession.checkPermission(PROVISION_PROJECTS, organization);
        RowBounds rowBounds = new RowBounds(options.getOffset(), options.getLimit());
        List<ComponentDto> projects = dbClient.componentDao().selectProvisioned(dbSession, organization.getUuid(), query, QUALIFIERS_FILTER, rowBounds);
        int nbOfProjects = dbClient.componentDao().countProvisioned(dbSession, organization.getUuid(), query, QUALIFIERS_FILTER);
        JsonWriter json = response.newJsonWriter().beginObject();
        writeProjects(projects, json, desiredFields);
        options.writeJson(json, nbOfProjects);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) RowBounds(org.apache.ibatis.session.RowBounds) SearchOptions(org.sonar.server.es.SearchOptions) JsonWriter(org.sonar.api.utils.text.JsonWriter) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 95 with ComponentDto

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

the class ProvisionedAction method writeProjects.

private static void writeProjects(List<ComponentDto> projects, JsonWriter json, Set<String> desiredFields) {
    json.name("projects");
    json.beginArray();
    for (ComponentDto project : projects) {
        json.beginObject();
        json.prop("uuid", project.uuid());
        writeIfNeeded(json, "key", project.key(), desiredFields);
        writeIfNeeded(json, "name", project.name(), desiredFields);
        writeIfNeeded(json, "creationDate", project.getCreatedAt(), desiredFields);
        json.endObject();
    }
    json.endArray();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto)

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