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();
}
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;
}
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;
}
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;
}
}
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;
}
}
Aggregations