Ejemplo n.º 1
0
 private String formatMeasure(@Nullable MeasureDto measure, Metric metric) {
   if (measure == null) {
     return null;
   }
   Metric.ValueType metricType = metric.getType();
   Double value = getDoubleValue(measure, metric);
   String data = measure.getData();
   if (value != null) {
     switch (metricType) {
       case FLOAT:
         return i18n.formatDouble(userSession.locale(), value);
       case INT:
         return i18n.formatInteger(userSession.locale(), value.intValue());
       case PERCENT:
         return i18n.formatDouble(userSession.locale(), value) + "%";
       case WORK_DUR:
         return durations.format(
             userSession.locale(),
             durations.create(value.longValue()),
             Durations.DurationFormat.SHORT);
     }
   }
   if ((metricType.equals(Metric.ValueType.STRING) || metricType.equals(Metric.ValueType.RATING))
       && data != null) {
     return data;
   }
   return null;
 }
Ejemplo n.º 2
0
  @Override
  public void define(WebService.NewController context) {
    WebService.NewAction action =
        context
            .createAction(ACTION)
            .setPost(true)
            .setDescription(
                "Update a custom metric.<br /> Requires 'Administer System' permission.")
            .setSince("5.2")
            .setHandler(this);

    action
        .createParam(PARAM_ID)
        .setRequired(true)
        .setDescription("Id of the custom metric to update")
        .setExampleValue("42");

    action.createParam(PARAM_NAME).setDescription("Name").setExampleValue("Team Size");

    action.createParam(PARAM_KEY).setDescription("Key").setExampleValue("team_size");

    action
        .createParam(PARAM_TYPE)
        .setDescription("Type")
        .setPossibleValues(Metric.ValueType.names());

    action
        .createParam(PARAM_DESCRIPTION)
        .setDescription("Description")
        .setExampleValue("Size of the team");

    action.createParam(PARAM_DOMAIN).setDescription("Domain").setExampleValue("Tests");
  }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 private static Metric.MetricType convert(org.sonar.api.measures.Metric.ValueType coreMetricType) {
   return Metric.MetricType.valueOf(coreMetricType.name());
 }