Example #1
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()));
     }
   }
 }