Search in sources :

Example 1 with QualityGateConditionDto

use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.

the class UpdateConditionAction method doHandle.

private UpdateConditionWsResponse doHandle(UpdateConditionRequest request, DbSession dbSession) {
    QualityGateConditionDto condition = qualityGateConditionsUpdater.updateCondition(dbSession, request.getConditionId(), request.getMetricKey(), request.getOperator(), request.getWarning(), request.getError(), request.getPeriod());
    UpdateConditionWsResponse.Builder response = UpdateConditionWsResponse.newBuilder().setId(condition.getId()).setMetric(condition.getMetricKey()).setOp(condition.getOperator());
    setNullable(condition.getWarningThreshold(), response::setWarning);
    setNullable(condition.getErrorThreshold(), response::setError);
    setNullable(condition.getPeriod(), response::setPeriod);
    return response.build();
}
Also used : UpdateConditionWsResponse(org.sonarqube.ws.WsQualityGates.UpdateConditionWsResponse) QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto)

Example 2 with QualityGateConditionDto

use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.

the class QualityGateConditionsUpdater method createCondition.

public QualityGateConditionDto createCondition(DbSession dbSession, long qGateId, String metricKey, String operator, @Nullable String warningThreshold, @Nullable String errorThreshold, @Nullable Integer period) {
    getNonNullQgate(dbSession, qGateId);
    MetricDto metric = getNonNullMetric(dbSession, metricKey);
    validateCondition(metric, operator, warningThreshold, errorThreshold, period);
    checkConditionDoesNotAlreadyExistOnSameMetricAndPeriod(getConditions(dbSession, qGateId, null), metric, period);
    QualityGateConditionDto newCondition = new QualityGateConditionDto().setQualityGateId(qGateId).setMetricId(metric.getId()).setMetricKey(metric.getKey()).setOperator(operator).setWarningThreshold(warningThreshold).setErrorThreshold(errorThreshold).setPeriod(period);
    dbClient.gateConditionDao().insert(newCondition, dbSession);
    return newCondition;
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto)

Example 3 with QualityGateConditionDto

use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.

the class QualityGateConditionsUpdater method updateCondition.

public QualityGateConditionDto updateCondition(DbSession dbSession, long condId, String metricKey, String operator, @Nullable String warningThreshold, @Nullable String errorThreshold, @Nullable Integer period) {
    QualityGateConditionDto condition = getNonNullCondition(dbSession, condId);
    MetricDto metric = getNonNullMetric(dbSession, metricKey);
    validateCondition(metric, operator, warningThreshold, errorThreshold, period);
    checkConditionDoesNotAlreadyExistOnSameMetricAndPeriod(getConditions(dbSession, condition.getQualityGateId(), condition.getId()), metric, period);
    condition.setMetricId(metric.getId()).setMetricKey(metric.getKey()).setOperator(operator).setWarningThreshold(warningThreshold).setErrorThreshold(errorThreshold).setPeriod(period);
    dbClient.gateConditionDao().update(condition, dbSession);
    return condition;
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto)

Example 4 with QualityGateConditionDto

use of org.sonar.db.qualitygate.QualityGateConditionDto 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 5 with QualityGateConditionDto

use of org.sonar.db.qualitygate.QualityGateConditionDto 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)

Aggregations

QualityGateConditionDto (org.sonar.db.qualitygate.QualityGateConditionDto)28 Test (org.junit.Test)16 MetricDto (org.sonar.db.metric.MetricDto)6 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)5 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)4 Metric (org.sonar.api.measures.Metric)3 ArrayList (java.util.ArrayList)2 DbSession (org.sonar.db.DbSession)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Before (org.junit.Before)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 CreateConditionWsResponse (org.sonarqube.ws.WsQualityGates.CreateConditionWsResponse)1 UpdateConditionWsResponse (org.sonarqube.ws.WsQualityGates.UpdateConditionWsResponse)1