checkPermission(userSession);
DbSession session = dbClient.openSession(false);
try {
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) {
throw new NotFoundException(String.format("Unknown sub characteristic '%s'", ruleChange.debtCharacteristicKey()));
}
}
boolean needUpdate = updateRule(ruleDto, subCharacteristic, ruleChange.debtRemediationFunction(), ruleChange.debtRemediationCoefficient(), ruleChange.debtRemediationOffset(),
session);