コード例 #1
0
 private Collection<QualityGateConditionDto> getConditions(
     DbSession dbSession, long qGateId, @Nullable Long conditionId) {
   Collection<QualityGateConditionDto> conditions =
       dbClient.gateConditionDao().selectForQualityGate(qGateId, dbSession);
   if (conditionId == null) {
     return conditions;
   }
   return dbClient
       .gateConditionDao()
       .selectForQualityGate(qGateId, dbSession)
       .stream()
       .filter(condition -> condition.getId() != conditionId)
       .collect(Collectors.toList());
 }
コード例 #2
0
  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;
  }
コード例 #3
0
 private QualityGateConditionDto getNonNullCondition(DbSession dbSession, long id) {
   QualityGateConditionDto condition = dbClient.gateConditionDao().selectById(id, dbSession);
   if (condition == null) {
     throw new NotFoundException("There is no condition with id=" + id);
   }
   return condition;
 }
コード例 #4
0
  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;
  }