this.dbClient = dbClient;
this.ruleActivator = ruleActivator;
}
public void delete(RuleKey ruleKey) {
DbSession dbSession = dbClient.openSession(false);
try {
RuleDto rule = dbClient.ruleDao().getByKey(dbSession, ruleKey);
if (rule.getTemplateId() == null && !rule.getRepositoryKey().equals(RuleDoc.MANUAL_REPOSITORY)) {
throw new IllegalStateException("Only custom rules and manual rules can be deleted");
}
// For custom rule, first deactivate the rule on all profiles
if (rule.getTemplateId() != null) {
ruleActivator.deactivate(dbSession, rule);
}
rule.setStatus(RuleStatus.REMOVED);
dbClient.ruleDao().update(dbSession, rule);
dbSession.commit();
} finally {
dbSession.close();
}
}