예제 #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();
 }
예제 #2
0
 private void checkNoOtherMetricWithTargetKey(
     DbSession dbSession, MetricDto metricInDb, MetricDto template) {
   String targetKey = template.getKey();
   MetricDto metricWithTargetKey = dbClient.metricDao().selectByKey(dbSession, targetKey);
   if (isMetricFoundInDb(metricWithTargetKey)
       && !metricInDb.getId().equals(metricWithTargetKey.getId())) {
     throw new BadRequestException(
         String.format("The key '%s' is already used by an existing metric.", targetKey));
   }
 }
예제 #3
0
  @Override
  public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn().checkPermission(GlobalPermissions.SYSTEM_ADMIN);
    int id = request.mandatoryParamAsInt(PARAM_ID);

    DbSession dbSession = dbClient.openSession(false);
    try {
      MetricDto metricTemplate = newMetricTemplate(request);
      MetricDto metricInDb = dbClient.metricDao().selectById(dbSession, id);
      checkMetricInDbAndTemplate(dbSession, metricInDb, metricTemplate);

      updateMetricInDb(dbSession, metricInDb, metricTemplate);
      JsonWriter json = response.newJsonWriter();
      writeMetric(json, metricInDb);
      json.close();
      rubyBridge.metricCache().invalidate();
    } finally {
      MyBatis.closeQuietly(dbSession);
    }
  }
 private void insertNewMetricDto(MetricDto metric) {
   dbClient.metricDao().insert(dbSession, metric);
   dbSession.commit();
 }