Package org.sonar.core.technicaldebt.db

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


  private void restoreRules(List<CharacteristicDto> allCharacteristicDtos, List<RuleDto> rules, List<RuleDebt> ruleDebts,
                            ValidationMessages validationMessages, Date updateDate, DbSession session) {
    for (RuleDto rule : rules) {
      RuleDebt ruleDebt = ruleDebt(rule.getRepositoryKey(), rule.getRuleKey(), ruleDebts);
      String subCharacteristicKey = ruleDebt != null ? ruleDebt.subCharacteristicKey() : null;
      CharacteristicDto subCharacteristicDto = subCharacteristicKey != null ? characteristicByKey(ruleDebt.subCharacteristicKey(), allCharacteristicDtos, true) : null;
      ruleOperations.updateRule(rule, subCharacteristicDto,
        ruleDebt != null ? ruleDebt.function() : null,
        ruleDebt != null ? ruleDebt.coefficient() : null,
        ruleDebt != null ? ruleDebt.offset() : null, session);
      rule.setUpdatedAt(updateDate);
View Full Code Here


    List<CharacteristicDto> result = newArrayList();

    // Create new characteristics
    for (DebtCharacteristic characteristic : targetModel.rootCharacteristics()) {
      CharacteristicDto rootCharacteristicDto = restoreCharacteristic(characteristic, null, sourceCharacteristics, updateDate, session);
      result.add(rootCharacteristicDto);
      for (DebtCharacteristic subCharacteristic : targetModel.subCharacteristics(characteristic.key())) {
        result.add(restoreCharacteristic(subCharacteristic, rootCharacteristicDto.getId(), sourceCharacteristics, updateDate, session));
      }
    }
    // Disable no more existing characteristics
    for (CharacteristicDto sourceCharacteristic : sourceCharacteristics) {
      if (targetModel.characteristicByKey(sourceCharacteristic.getKey()) == null) {
View Full Code Here

    return result;
  }

  private CharacteristicDto restoreCharacteristic(DebtCharacteristic targetCharacteristic, @Nullable Integer parentId, List<CharacteristicDto> sourceCharacteristics,
                                                  Date updateDate, DbSession session) {
    CharacteristicDto sourceCharacteristic = characteristicByKey(targetCharacteristic.key(), sourceCharacteristics, false);
    if (sourceCharacteristic == null) {
      CharacteristicDto newCharacteristic = toDto(targetCharacteristic, parentId).setCreatedAt(updateDate);
      dbClient.debtCharacteristicDao().insert(newCharacteristic, session);
      return newCharacteristic;
    } else {
      // Update only if modifications
      if (ObjectUtils.notEqual(sourceCharacteristic.getName(), targetCharacteristic.name()) ||
View Full Code Here

  private static CharacteristicDto characteristicByKey(@Nullable final String key, List<CharacteristicDto> characteristicDtos, boolean failIfNotFound) {
    if (key == null) {
      return null;
    }
    CharacteristicDto dto = Iterables.find(characteristicDtos, new Predicate<CharacteristicDto>() {
      @Override
      public boolean apply(@Nullable CharacteristicDto input) {
        return input != null && key.equals(input.getKey());
      }
    }, null);
View Full Code Here

    }
    return null;
  }

  private static CharacteristicDto toDto(DebtCharacteristic characteristic, @Nullable Integer parentId) {
    return new CharacteristicDto()
      .setKey(characteristic.key())
      .setName(characteristic.name())
      .setOrder(characteristic.order())
      .setParentId(parentId)
      .setEnabled(true)
View Full Code Here

        throw new IllegalArgumentException("Rule with REMOVED status cannot be updated: " + change.getRuleKey());
      }
      String subCharacteristicKey = change.getDebtSubCharacteristicKey();
      if (subCharacteristicKey != null &&
        !subCharacteristicKey.equals(RuleUpdate.DEFAULT_DEBT_CHARACTERISTIC)) {
        CharacteristicDto characteristicDto = dbClient.debtCharacteristicDao().selectByKey(subCharacteristicKey, dbSession);
        if (characteristicDto == null) {
          throw new IllegalArgumentException("Unknown debt sub-characteristic: " + subCharacteristicKey);
        }
        if (!characteristicDto.isEnabled()) {
          throw new IllegalArgumentException("Debt sub-characteristic is disabled: " + subCharacteristicKey);
        }
        if (characteristicDto.getParentId() == null) {
          throw new IllegalArgumentException("Not a sub-characteristic: " + subCharacteristicKey);
        }
        context.newCharacteristic = characteristicDto;
      }
      return context;
View Full Code Here

      update.put(RuleField.DEFAULT_CHARACTERISTIC.field(), null);
      update.put(RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), null);

      Integer defaultSubCharacteristicId = rule.getDefaultSubCharacteristicId();
      if (defaultSubCharacteristicId != null) {
        CharacteristicDto subCharacteristic = db.debtCharacteristicDao().selectById(defaultSubCharacteristicId, session);
        if (subCharacteristic != null) {
          Integer characteristicId = subCharacteristic.getParentId();
          if (characteristicId != null) {
            CharacteristicDto characteristic = db.debtCharacteristicDao().selectById(characteristicId);
            if (characteristic != null) {
              update.put(RuleField.DEFAULT_CHARACTERISTIC.field(), characteristic.getKey());
              update.put(RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), subCharacteristic.getKey());
            }
          }
        }
      }

      Integer subCharacteristicId = rule.getSubCharacteristicId();
      if (subCharacteristicId != null) {
        if (subCharacteristicId.equals(-1)) {
          update.put(RuleField.CHARACTERISTIC.field(), DebtCharacteristic.NONE);
          update.put(RuleField.SUB_CHARACTERISTIC.field(), DebtCharacteristic.NONE);
        } else {
          CharacteristicDto subCharacteristic = db.debtCharacteristicDao().selectById(subCharacteristicId, session);
          if (subCharacteristic != null) {
            Integer characteristicId = subCharacteristic.getParentId();
            if (characteristicId != null) {
              CharacteristicDto characteristic = db.debtCharacteristicDao().selectById(characteristicId);
              if (characteristic != null) {
                update.put(RuleField.CHARACTERISTIC.field(), characteristic.getKey());
                update.put(RuleField.SUB_CHARACTERISTIC.field(), subCharacteristic.getKey());
              }
            }
          }
        }
View Full Code Here

    verify(debtModelBackup).reset();
  }

  @Test
  public void not_create_debt_model_if_already_exists() throws Exception {
    when(dao.selectEnabledCharacteristics()).thenReturn(newArrayList(new CharacteristicDto()));

    registerDebtModel.start();

    verifyZeroInteractions(debtModelBackup);
  }
View Full Code Here

    currentId = 10;
    // Associate an id when inserting an object to simulate the db id generator
    doAnswer(new Answer() {
      public Object answer(InvocationOnMock invocation) {
        Object[] args = invocation.getArguments();
        CharacteristicDto dto = (CharacteristicDto) args[0];
        dto.setId(++currentId);
        return null;
      }
    }).when(dao).insert(any(CharacteristicDto.class), any(SqlSession.class));

    when(dbClient.openSession(false)).thenReturn(session);
View Full Code Here

    }
  }

  @Test
  public void fail_to_create_sub_characteristic_when_name_already_used() {
    when(dao.selectByName("Compilation", session)).thenReturn(new CharacteristicDto());
    when(dao.selectById(1, session)).thenReturn(characteristicDto);

    try {
      service.create("Compilation", 1);
      fail();
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.