Search in sources :

Example 76 with DbSession

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

the class QualityGates method rename.

public QualityGateDto rename(long idToRename, String name) {
    checkIsSystemAdministrator();
    try (DbSession dbSession = dbClient.openSession(false)) {
        QualityGateDto toRename = getNonNullQgate(idToRename);
        validateQualityGate(dbSession, idToRename, name);
        toRename.setName(name);
        dao.update(toRename, dbSession);
        dbSession.commit();
        return toRename;
    }
}
Also used : DbSession(org.sonar.db.DbSession) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 77 with DbSession

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

the class QualityGates method listConditions.

public Collection<QualityGateConditionDto> listConditions(long qGateId) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        Collection<QualityGateConditionDto> conditionsForGate = conditionDao.selectForQualityGate(dbSession, qGateId);
        for (QualityGateConditionDto condition : conditionsForGate) {
            Metric metric = metricFinder.findById((int) condition.getMetricId());
            if (metric == null) {
                throw new IllegalStateException("Could not find metric with id " + condition.getMetricId());
            }
            condition.setMetricKey(metric.getKey());
        }
        return conditionsForGate;
    }
}
Also used : DbSession(org.sonar.db.DbSession) QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Metric(org.sonar.api.measures.Metric)

Example 78 with DbSession

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

the class QualityGates method copy.

public QualityGateDto copy(long sourceId, String destinationName) {
    checkIsSystemAdministrator();
    getNonNullQgate(sourceId);
    try (DbSession dbSession = dbClient.openSession(false)) {
        validateQualityGate(dbSession, null, destinationName);
        QualityGateDto destinationGate = new QualityGateDto().setName(destinationName);
        dao.insert(dbSession, destinationGate);
        for (QualityGateConditionDto sourceCondition : conditionDao.selectForQualityGate(dbSession, sourceId)) {
            conditionDao.insert(new QualityGateConditionDto().setQualityGateId(destinationGate.getId()).setMetricId(sourceCondition.getMetricId()).setOperator(sourceCondition.getOperator()).setWarningThreshold(sourceCondition.getWarningThreshold()).setErrorThreshold(sourceCondition.getErrorThreshold()).setPeriod(sourceCondition.getPeriod()), dbSession);
        }
        dbSession.commit();
        return destinationGate;
    }
}
Also used : DbSession(org.sonar.db.DbSession) QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 79 with DbSession

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

the class RegisterQualityGates method start.

@Override
public void start() {
    try (DbSession dbSession = dbClient.openSession(false)) {
        if (shouldRegisterBuiltinQualityGate(dbSession)) {
            createBuiltinQualityGate(dbSession);
            registerBuiltinQualityGate(dbSession);
            dbSession.commit();
        }
    }
}
Also used : DbSession(org.sonar.db.DbSession)

Example 80 with DbSession

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

the class DeselectAction method handle.

@Override
public void handle(Request request, Response response) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto project = getProject(dbSession, request.param(PARAM_PROJECT_ID), request.param(PARAM_PROJECT_KEY));
        qualityGates.dissociateProject(dbSession, QualityGatesWs.parseId(request, QualityGatesWsParameters.PARAM_GATE_ID), project);
        response.noContent();
    }
}
Also used : DbSession(org.sonar.db.DbSession) 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