예제 #1
0
 private void updateMetricInDb(
     DbSession dbSession, MetricDto metricInDb, MetricDto metricTemplate) {
   String key = metricTemplate.getKey();
   String name = metricTemplate.getShortName();
   String type = metricTemplate.getValueType();
   String domain = metricTemplate.getDomain();
   String description = metricTemplate.getDescription();
   if (key != null) {
     metricInDb.setKey(key);
   }
   if (name != null) {
     metricInDb.setShortName(name);
   }
   if (type != null) {
     metricInDb.setValueType(type);
   }
   if (domain != null) {
     metricInDb.setDomain(domain);
   }
   if (description != null) {
     metricInDb.setDescription(description);
   }
   dbClient.metricDao().update(dbSession, metricInDb);
   dbSession.commit();
 }
 private static void checkRatingMetric(
     MetricDto metric,
     @Nullable String warningThreshold,
     @Nullable String errorThreshold,
     @Nullable Integer period,
     Errors errors) {
   if (!metric.getValueType().equals(RATING.name())) {
     return;
   }
   if (period != null && !metric.getKey().startsWith("new_")) {
     errors.add(
         Message.of(
             format("The metric '%s' cannot be used on the leak period", metric.getShortName())));
   }
   if (!isValidRating(warningThreshold)) {
     addInvalidRatingError(warningThreshold, errors);
     return;
   }
   if (!isValidRating(errorThreshold)) {
     addInvalidRatingError(errorThreshold, errors);
     return;
   }
   checkRatingGreaterThanOperator(warningThreshold, errors);
   checkRatingGreaterThanOperator(errorThreshold, errors);
 }
예제 #3
0
 private static void writeMetric(JsonWriter json, MetricDto metric) {
   json.beginObject();
   json.prop(FIELD_ID, String.valueOf(metric.getId()));
   json.prop(FIELD_KEY, metric.getKey());
   json.prop(FIELD_TYPE, metric.getValueType());
   json.prop(FIELD_NAME, metric.getShortName());
   json.prop(FIELD_DOMAIN, metric.getDomain());
   json.prop(FIELD_DESCRIPTION, metric.getDescription());
   json.endObject();
 }
예제 #4
0
 @Override
 public Metric apply(@Nonnull MetricDto dto) {
   Metric<Serializable> metric = new Metric<>();
   metric.setId(dto.getId());
   metric.setKey(dto.getKey());
   metric.setDescription(dto.getDescription());
   metric.setName(dto.getShortName());
   metric.setBestValue(dto.getBestValue());
   metric.setDomain(dto.getDomain());
   metric.setEnabled(dto.isEnabled());
   metric.setDirection(dto.getDirection());
   metric.setHidden(dto.isHidden());
   metric.setQualitative(dto.isQualitative());
   metric.setType(Metric.ValueType.valueOf(dto.getValueType()));
   metric.setOptimizedBestValue(dto.isOptimizedBestValue());
   metric.setUserManaged(dto.isUserManaged());
   metric.setWorstValue(dto.getWorstValue());
   return metric;
 }
예제 #5
0
 private void checkMetricInDbAndTemplate(
     DbSession dbSession, @Nullable MetricDto metricInDb, MetricDto template) {
   if (!isMetricFoundInDb(metricInDb)
       || isMetricDisabled(metricInDb)
       || !isMetricCustom(metricInDb)) {
     throw new BadRequestException(
         String.format("No active custom metric has been found for id '%d'.", template.getId()));
   }
   checkNoOtherMetricWithTargetKey(dbSession, metricInDb, template);
   if (haveMetricTypeChanged(metricInDb, template)) {
     List<CustomMeasureDto> customMeasures =
         dbClient.customMeasureDao().selectByMetricId(dbSession, metricInDb.getId());
     if (haveAssociatedCustomMeasures(customMeasures)) {
       throw new BadRequestException(
           String.format(
               "You're trying to change the type '%s' while there are associated custom measures.",
               metricInDb.getValueType()));
     }
   }
 }
예제 #6
0
 private static boolean haveMetricTypeChanged(MetricDto metricInDb, MetricDto template) {
   return !metricInDb.getValueType().equals(template.getValueType())
       && template.getValueType() != null;
 }
 private static void checkOperator(MetricDto metric, String operator, Errors errors) {
   ValueType valueType = valueOf(metric.getValueType());
   errors.check(
       isOperatorAllowed(operator, valueType),
       format("Operator %s is not allowed for metric type %s.", operator, metric.getValueType()));
 }