.setDescription(ruleDto.getDescription())
.setStatus(RuleStatus.valueOf(ruleDto.getStatus()));
// TODO should we set metadata ?
- Integer characteristicId = ruleDto.getCharacteristicId();
- Integer defaultCharacteristicId = ruleDto.getDefaultCharacteristicId();
- if (characteristicId != null) {
- Characteristic characteristic = characteristic(characteristicId, ruleKey, debtModel);
- updateRuleDebtDefinitions(newRule, ruleKey, characteristic, ruleDto.getRemediationFunction(), ruleDto.getRemediationFactor(), ruleDto.getRemediationOffset(), durations);
- } else if (defaultCharacteristicId != null) {
- Characteristic characteristic = characteristic(defaultCharacteristicId, ruleKey, debtModel);
- updateRuleDebtDefinitions(newRule, ruleKey, characteristic, ruleDto.getDefaultRemediationFunction(), ruleDto.getDefaultRemediationFactor(),
- ruleDto.getDefaultRemediationOffset(), durations);
+ if (!ruleDto.isCharacteristicDisabled()) {
+ Integer characteristicId = ruleDto.getCharacteristicId();
+ Integer defaultCharacteristicId = ruleDto.getDefaultCharacteristicId();
+ if (characteristicId != null) {
+ Characteristic characteristic = characteristic(characteristicId, ruleKey, debtModel);
+ updateRuleDebtDefinitions(newRule, ruleKey, characteristic, ruleDto.getRemediationFunction(), ruleDto.getRemediationFactor(), ruleDto.getRemediationOffset(), durations);
+ } else if (defaultCharacteristicId != null) {
+ Characteristic characteristic = characteristic(defaultCharacteristicId, ruleKey, debtModel);
+ updateRuleDebtDefinitions(newRule, ruleKey, characteristic, ruleDto.getDefaultRemediationFunction(), ruleDto.getDefaultRemediationFactor(),
+ ruleDto.getDefaultRemediationOffset(), durations);
+ }
}
for (RuleParamDto ruleParamDto : paramDtosByRuleId.get(ruleDto.getId())) {
newRule.addParam(ruleParamDto.getName())
assertThat(rule.offset()).isNull();
}
+ @Test
+ public void build_rules_with_disable_characteristic() throws Exception {
+ setupData("build_rules_with_disable_characteristic");
+
+ Rules rules = provider.provide(ruleDao, debtModel, durations);
+
+ Rule rule = rules.find(RuleKey.of("checkstyle", "AvoidNull"));
+ assertThat(rule.characteristic()).isNull();
+ assertThat(rule.function()).isNull();
+ assertThat(rule.factor()).isNull();
+ assertThat(rule.offset()).isNull();
+ }
+
@Test
public void fail_if_characteristic_not_found() throws Exception {
setupData("fail_if_characteristic_not_found");
public final class RuleDto {
- public final static Integer DISABLED_CHARACTERISTIC_ID = -1;
+ public static final Integer DISABLED_CHARACTERISTIC_ID = -1;
private Integer id;
private String repositoryKey;
return this;
}
- public boolean isCharacteristicOverridden(){
- return !DISABLED_CHARACTERISTIC_ID.equals(characteristicId);
+ public boolean isCharacteristicDisabled(){
+ return DISABLED_CHARACTERISTIC_ID.equals(characteristicId);
}
@Override