/**
* @return enabled root characteristics, characteristics and requirements
+ *
+ * @deprecated since 4.3
*/
+ @Deprecated
public List<CharacteristicDto> selectEnabledCharacteristics() {
SqlSession session = mybatis.openSession();
try {
- return selectEnabledCharacteristics(session);
+ return session.getMapper(CharacteristicMapper.class).selectEnabledCharacteristics();
} finally {
MyBatis.closeQuietly(session);
}
}
- public List<CharacteristicDto> selectEnabledCharacteristics(SqlSession session) {
- return session.getMapper(CharacteristicMapper.class).selectEnabledCharacteristics();
+ /**
+ * @return enabled root characteristics, and characteristics
+ *
+ */
+ public List<CharacteristicDto> selectCharacteristics() {
+ SqlSession session = mybatis.openSession();
+ try {
+ return selectCharacteristics(session);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public List<CharacteristicDto> selectCharacteristics(SqlSession session) {
+ return session.getMapper(CharacteristicMapper.class).selectCharacteristics();
}
/**
List<CharacteristicDto> selectEnabledCharacteristics();
+ List<CharacteristicDto> selectCharacteristics();
+
List<CharacteristicDto> selectEnabledRootCharacteristics();
CharacteristicDto selectByKey(String key);
</where>
</select>
+ <select id="selectCharacteristics" parameterType="map" resultType="Characteristic">
+ select <include refid="characteristicColumns"/>
+ from characteristics c
+ <where>
+ and c.rule_id is null
+ and c.enabled=${_true}
+ </where>
+ </select>
+
<select id="selectEnabledRootCharacteristics" parameterType="map" resultType="Characteristic">
select <include refid="characteristicColumns"/>
from characteristics c
assertThat(requirement.getUpdatedAt()).isNull();
}
+ @Test
+ public void select_characteristics() {
+ setupData("shared");
+
+ List<CharacteristicDto> dtos = dao.selectCharacteristics();
+
+ assertThat(dtos).hasSize(2);
+
+ CharacteristicDto rootCharacteristic = dtos.get(0);
+ assertThat(rootCharacteristic.getId()).isEqualTo(1);
+ assertThat(rootCharacteristic.getKey()).isEqualTo("PORTABILITY");
+ assertThat(rootCharacteristic.getName()).isEqualTo("Portability");
+ assertThat(rootCharacteristic.getParentId()).isNull();
+ assertThat(rootCharacteristic.getRootId()).isNull();
+ assertThat(rootCharacteristic.getOrder()).isEqualTo(1);
+ assertThat(rootCharacteristic.isEnabled()).isTrue();
+ assertThat(rootCharacteristic.getCreatedAt()).isNotNull();
+ assertThat(rootCharacteristic.getUpdatedAt()).isNotNull();
+
+ CharacteristicDto characteristic = dtos.get(1);
+ assertThat(characteristic.getId()).isEqualTo(2);
+ assertThat(characteristic.getKey()).isEqualTo("COMPILER_RELATED_PORTABILITY");
+ assertThat(characteristic.getName()).isEqualTo("Compiler related portability");
+ assertThat(characteristic.getParentId()).isEqualTo(1);
+ assertThat(characteristic.getRootId()).isEqualTo(1);
+ assertThat(characteristic.getOrder()).isNull();
+ assertThat(characteristic.isEnabled()).isTrue();
+ assertThat(characteristic.getCreatedAt()).isNotNull();
+ assertThat(characteristic.getUpdatedAt()).isNotNull();
+ }
+
@Test
public void select_enabled_root_characteristics() {
setupData("select_enabled_root_characteristics");
try {
RuleDefinitions.Context context = defLoader.load();
Buffer buffer = new Buffer(system.now());
- List<CharacteristicDto> characteristicDtos = characteristicDao.selectEnabledCharacteristics();
+ List<CharacteristicDto> characteristicDtos = characteristicDao.selectCharacteristics();
selectRulesFromDb(buffer, sqlSession);
enableRuleDefinitions(context, buffer, characteristicDtos, sqlSession);
List<RuleDto> removedRules = processRemainingDbRules(buffer, sqlSession);
@Override
public boolean apply(CharacteristicDto input) {
String characteristicKey = input.getKey();
- // TODO remove check on null rule id when only characteristics without requirements will be returned
- return input.getRuleId() == null && characteristicKey != null && characteristicKey.equals(key);
+ return characteristicKey != null && characteristicKey.equals(key);
}
}, null);
- // TODO check not root characteristic
+
if (characteristicDto == null) {
- LOG.warn(String.format("Characteristic : '%s' has not been found, Technical debt definitions on rule '%s:%s' will be ignored", key,
+ LOG.warn(String.format("Characteristic '%s' has not been found, Technical debt definitions on rule '%s:%s' will be ignored",
+ key, ruleDef.repository().name(), ruleDef.key()));
+ } else if (characteristicDto.getParentId() == null) {
+ LOG.error(String.format("Rule '%s:%s' should not be linked on the root characteristic '%s'. Technical debt definitions on this rule wll be ignored", key,
ruleDef.repository().name(), ruleDef.key()));
+ return null;
}
return characteristicDto;
}
checkTables("remove_rule_debt_definitions_if_characteristic_not_found", EXCLUDED_COLUMN_NAMES, "rules");
}
+ @Test
+ public void ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic() {
+ setupData("ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic");
+ task.start();
+
+ checkTables("ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic", EXCLUDED_COLUMN_NAMES, "rules");
+ }
+
@Test
public void not_disable_template_rules_if_parent_is_enabled() {
setupData("not_disable_template_rules_if_parent_is_enabled");
--- /dev/null
+<dataset>
+
+ <rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="config1" name="One" description="Description of One"
+ status="READY" priority="4" cardinality="SINGLE" parent_id="[null]" language="java"
+ characteristic_id="[null]" default_characteristic_id="[null]"
+ remediation_function="[null]" default_remediation_function="[null]"
+ remediation_factor="[null]" default_remediation_factor="[null]"
+ remediation_offset="[null]" default_remediation_offset="[null]"
+ effort_to_fix_l10n_key="[null]"/>
+
+ <rules id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
+ status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"
+ characteristic_id="[null]" default_characteristic_id="[null]"
+ remediation_function="[null]" default_remediation_function="[null]"
+ remediation_factor="[null]" default_remediation_factor="[null]"
+ remediation_offset="[null]" default_remediation_offset="[null]"
+ effort_to_fix_l10n_key="[null]"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <characteristics id="2" kee="MEMORY_EFFICIENCY" name="Efficiency" root_id="[null]" characteristic_order="[null]" enabled="[true]"/>
+
+ <rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="old_config_key" name="old name" description="old description"
+ status="READY" priority="2" cardinality="SINGLE" parent_id="[null]"
+ characteristic_id="[null]" default_characteristic_id="200"
+ remediation_function="[null]" default_remediation_function="LINEAR"
+ remediation_factor="[null]" default_remediation_factor="14min"
+ remediation_offset="[null]" default_remediation_offset="[null]"
+ effort_to_fix_l10n_key="squid.S1115.effortTotFix"/>
+
+ <rules id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="old_config_key2" name="old name2" description="old description2"
+ status="READY" priority="1" cardinality="SINGLE" parent_id="[null]"/>
+
+
+</dataset>
<dataset>
- <characteristics id="2" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" root_id="1" characteristic_order="1" enabled="[true]"/>
+ <characteristics id="2" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" parent_id="1" root_id="1" characteristic_order="1" enabled="[true]"/>
<rules id="1" plugin_rule_key="deprecated-key" plugin_name="deprecated-repo" plugin_config_key="[null]" name="Deprecated" description="[null]"
status="READY" priority="4" cardinality="SINGLE" parent_id="[null]"/>
<dataset>
- <characteristics id="200" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" root_id="1" characteristic_order="1" enabled="[true]"/>
+ <characteristics id="200" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" root_id="1" parent_id="1" characteristic_order="1" enabled="[true]"/>
<rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="old_config_key" name="old name" description="old description"
status="READY" priority="2" cardinality="SINGLE" parent_id="[null]"
<dataset>
- <characteristics id="100" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" root_id="1" characteristic_order="1" enabled="[true]"/>
+ <characteristics id="100" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" root_id="1" parent_id="1" characteristic_order="1" enabled="[true]"/>
<rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="[null]" name="Rule one" description="[null]"
status="READY" priority="4" cardinality="MULTIPLE" parent_id="[null]" language="[null]"