import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.ibatis.session.SqlSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.debt.DebtCharacteristic;
public class DebtModelBackup implements ServerComponent {
+ private static final Logger LOG = LoggerFactory.getLogger(DebtModelBackup.class);
+
private final MyBatis mybatis;
private final CharacteristicDao dao;
private final RuleDao ruleDao;
session.commit();
} catch (IllegalArgumentException e) {
+ LOG.debug("Error when restoring the model", e);
validationMessages.addErrorText(e.getMessage());
} finally {
MyBatis.closeQuietly(session);
debtModel.characteristicById(effectiveSubCharacteristicId) : null;
if (subCharacteristic != null) {
ruleDebt.setSubCharacteristicKey(subCharacteristic.key());
- if (rule.getRemediationFunction() != null) {
- ruleDebt.setFunction(rule.getRemediationFunction());
+
+ String overriddenFunction = rule.getRemediationFunction();
+ String defaultFunction = rule.getDefaultRemediationFunction();
+ if (overriddenFunction != null) {
+ ruleDebt.setFunction(overriddenFunction);
ruleDebt.setCoefficient(rule.getRemediationCoefficient());
ruleDebt.setOffset(rule.getRemediationOffset());
return ruleDebt;
- } else if (rule.getDefaultRemediationFunction() != null) {
- ruleDebt.setFunction(rule.getDefaultRemediationFunction());
+ } else if (defaultFunction != null) {
+ ruleDebt.setFunction(defaultFunction);
ruleDebt.setCoefficient(rule.getDefaultRemediationCoefficient());
ruleDebt.setOffset(rule.getDefaultRemediationOffset());
return ruleDebt;
Integer effectiveSubCharacteristicId = rule.getSubCharacteristicId() != null ? rule.getSubCharacteristicId() : rule.getDefaultSubCharacteristicId();
CharacteristicDto subCharacteristic = effectiveSubCharacteristicId != null ? characteristicDao.selectById(effectiveSubCharacteristicId, session) : null;
// The parent id of the sub-characteristic should never be null
- CharacteristicDto characteristic = (subCharacteristic != null && subCharacteristic.getParentId() != null) ?
- characteristicDao.selectById(subCharacteristic.getParentId(), session) : null;
+ Integer parentId = subCharacteristic!= null ? subCharacteristic.getParentId() : null;
+ CharacteristicDto characteristic = (subCharacteristic != null && parentId != null) ?
+ characteristicDao.selectById(parentId, session) : null;
searchIndex.putSynchronous(INDEX_RULES, TYPE_RULE, Long.toString(ruleId), ruleDocument(rule,
characteristic, subCharacteristic,
ruleDao.selectParametersByRuleIds(newArrayList(ruleId), session),