Search in sources :

Example 66 with DbSession

use of org.sonar.db.DbSession 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 67 with DbSession

use of org.sonar.db.DbSession 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 68 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class SelectAction method doHandle.

private void doHandle(SelectWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        checkQualityGate(dbSession, request.getGateId());
        ComponentDto project = getProject(dbSession, request.getProjectId(), request.getProjectKey());
        dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(SONAR_QUALITYGATE_PROPERTY).setResourceId(project.getId()).setValue(String.valueOf(request.getGateId())));
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) PropertyDto(org.sonar.db.property.PropertyDto)

Example 69 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class CreateEventAction method doHandle.

private CreateEventResponse doHandle(CreateEventRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        SnapshotDto analysis = getAnalysis(dbSession, request);
        checkExistingDbEvents(dbSession, request, analysis);
        EventDto dbEvent = insertDbEvent(dbSession, request, analysis);
        return toCreateEventResponse(dbEvent);
    }
}
Also used : DbSession(org.sonar.db.DbSession) SnapshotDto(org.sonar.db.component.SnapshotDto) EventDto(org.sonar.db.event.EventDto)

Example 70 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class CreateAction method doHandle.

private CreateWsResponse doHandle(CreateWsRequest createWsRequest) {
    validateRequest(createWsRequest);
    String name = createWsRequest.getName();
    String url = createWsRequest.getUrl();
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = getComponentByUuidOrKey(dbSession, createWsRequest);
        userSession.checkComponentPermission(UserRole.ADMIN, component);
        ComponentLinkDto link = new ComponentLinkDto().setComponentUuid(component.uuid()).setName(name).setHref(url).setType(nameToType(name));
        dbClient.componentLinkDao().insert(dbSession, link);
        dbSession.commit();
        return buildResponse(link);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentLinkDto(org.sonar.db.component.ComponentLinkDto) ComponentDto(org.sonar.db.component.ComponentDto)

Aggregations

DbSession (org.sonar.db.DbSession)254 ComponentDto (org.sonar.db.component.ComponentDto)63 OrganizationDto (org.sonar.db.organization.OrganizationDto)30 JsonWriter (org.sonar.api.utils.text.JsonWriter)24 UserDto (org.sonar.db.user.UserDto)20 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)16 Test (org.junit.Test)13 MetricDto (org.sonar.db.metric.MetricDto)13 Paging (org.sonar.api.utils.Paging)12 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)10 CeQueueDto (org.sonar.db.ce.CeQueueDto)8 DepthTraversalTypeAwareCrawler (org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)8 SearchOptions (org.sonar.server.es.SearchOptions)8 NotFoundException (org.sonar.server.exceptions.NotFoundException)8 List (java.util.List)7 SnapshotDto (org.sonar.db.component.SnapshotDto)7 GroupDto (org.sonar.db.user.GroupDto)7 DbClient (org.sonar.db.DbClient)6 ProjectId (org.sonar.server.permission.ProjectId)6 RuleKey (org.sonar.api.rule.RuleKey)5