Package org.sonar.core.technicaldebt.db

Examples of org.sonar.core.technicaldebt.db.CharacteristicDto


    SqlSession session = dbClient.openSession(false);
    try {
      checkNotAlreadyExists(name, session);

      CharacteristicDto newCharacteristic = new CharacteristicDto()
        .setKey(name.toUpperCase().replace(" ", "_"))
        .setName(name)
        .setEnabled(true)
        .setCreatedAt(new Date(system2.now()));

      // New sub characteristic
      if (parentId != null) {
        CharacteristicDto parent = findCharacteristic(parentId, session);
        if (parent.getParentId() != null) {
          throw new BadRequestException("A sub characteristic can not have a sub characteristic as parent.");
        }
        newCharacteristic.setParentId(parent.getId());
      } else {
        // New root characteristic
        newCharacteristic.setOrder(dbClient.debtCharacteristicDao().selectMaxCharacteristicOrder(session) + 1);
      }
      dbClient.debtCharacteristicDao().insert(newCharacteristic, session);
View Full Code Here


    SqlSession session = dbClient.openSession(false);
    try {
      checkNotAlreadyExists(newName, session);

      CharacteristicDto dto = findCharacteristic(characteristicId, session);
      if (!dto.getName().equals(newName)) {
        dto.setName(newName);
        dto.setUpdatedAt(new Date(system2.now()));
        dbClient.debtCharacteristicDao().update(dto, session);
        session.commit();
      }
      return toCharacteristic(dto);
    } finally {
View Full Code Here

  private DebtCharacteristic move(int characteristicId, boolean moveUpOrDown) {
    checkPermission();

    SqlSession session = dbClient.openSession(false);
    try {
      final CharacteristicDto dto = findCharacteristic(characteristicId, session);
      if (dto.getParentId() != null) {
        throw new BadRequestException("Sub characteristics can not be moved.");
      }
      int currentOrder = getOrder(dto);
      CharacteristicDto dtoToSwitchOrderWith = findCharacteristicToSwitchWith(dto, moveUpOrDown, session);

      // Do nothing when characteristic is already to the good location
      if (dtoToSwitchOrderWith == null) {
        return toCharacteristic(dto);
      }

      int nextOrder = getOrder(dtoToSwitchOrderWith);
      dtoToSwitchOrderWith.setOrder(currentOrder);
      dtoToSwitchOrderWith.setUpdatedAt(new Date(system2.now()));
      dbClient.debtCharacteristicDao().update(dtoToSwitchOrderWith, session);

      dto.setOrder(nextOrder);
      dto.setUpdatedAt(new Date(system2.now()));
      dbClient.debtCharacteristicDao().update(dto, session);
View Full Code Here

      dbClient.ruleDao().update(session, ruleDto);
    }
  }

  private CharacteristicDto findCharacteristic(Integer id, SqlSession session) {
    CharacteristicDto dto = dbClient.debtCharacteristicDao().selectById(id, session);
    if (dto == null) {
      throw new NotFoundException(String.format("Characteristic with id %s does not exists.", id));
    }
    return dto;
  }
View Full Code Here

    return toCharacteristics(dao.selectEnabledCharacteristics());
  }

  @CheckForNull
  public DebtCharacteristic characteristicById(int id) {
    CharacteristicDto dto = dao.selectById(id);
    return dto != null ? toCharacteristic(dto) : null;
  }
View Full Code Here

    return dto != null ? toCharacteristic(dto) : null;
  }

  @CheckForNull
  public DebtCharacteristic characteristicByKey(String key) {
    CharacteristicDto dto = dao.selectByKey(key);
    return dto != null ? toCharacteristic(dto) : null;
  }
View Full Code Here

    boolean executeUpdate = false;
    if (mergeRule(ruleDef, rule)) {
      executeUpdate = true;
    }

    CharacteristicDto subCharacteristic = characteristic(ruleDef, rule.getSubCharacteristicId(), allCharacteristics);
    if (mergeDebtDefinitions(ruleDef, rule, subCharacteristic)) {
      executeUpdate = true;
    }

    if (mergeTags(ruleDef, rule)) {
View Full Code Here

    // Rule is not linked to a default characteristic or characteristic has been disabled by user
    if (subCharacteristic == null) {
      return null;
    }
    CharacteristicDto characteristicDto = allCharacteristics.get(subCharacteristic);
    if (characteristicDto == null) {
      // Log a warning only if rule has not been overridden by user
      if (overridingCharacteristicId == null) {
        LOG.warn(String.format("Characteristic '%s' has not been found on rule '%s:%s'", subCharacteristic, repo, ruleKey));
      }
    } else if (characteristicDto.getParentId() == null) {
      throw MessageException.of(String.format("Rule '%s:%s' cannot be linked on the root characteristic '%s'", repo, ruleKey, subCharacteristic));
    }
    return characteristicDto;
  }
View Full Code Here

      RuleDto ruleDto = dbClient.ruleDao().getNullableByKey(session, ruleChange.ruleKey());
      if (ruleDto == null) {
        throw new NotFoundException(String.format("Unknown rule '%s'", ruleChange.ruleKey()));
      }
      String subCharacteristicKey = ruleChange.debtCharacteristicKey();
      CharacteristicDto subCharacteristic = null;

      // A sub-characteristic is given -> update rule debt if given values are different from overridden ones and from default ones
      if (!Strings.isNullOrEmpty(subCharacteristicKey)) {
        subCharacteristic = dbClient.debtCharacteristicDao().selectByKey(subCharacteristicKey, session);
        if (subCharacteristic == null) {
View Full Code Here

        ruleDef = ruleDef(rule.getRepositoryKey(), rule.getRuleKey(), rules);
      }

      if (ruleDef != null) {
        String subCharacteristicKey = ruleDef.debtSubCharacteristic();
        CharacteristicDto subCharacteristicDto = characteristicByKey(subCharacteristicKey, allCharacteristicDtos, false);
        DebtRemediationFunction remediationFunction = ruleDef.debtRemediationFunction();
        boolean hasDebtDefinition = subCharacteristicDto != null && remediationFunction != null;

        rule.setDefaultSubCharacteristicId(hasDebtDefinition ? subCharacteristicDto.getId() : null);
        rule.setDefaultRemediationFunction(hasDebtDefinition ? remediationFunction.type().name() : null);
        rule.setDefaultRemediationCoefficient(hasDebtDefinition ? remediationFunction.coefficient() : null);
        rule.setDefaultRemediationOffset(hasDebtDefinition ? remediationFunction.offset() : null);
      }
View Full Code Here

TOP

Related Classes of org.sonar.core.technicaldebt.db.CharacteristicDto

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.