private ActiveRuleDto persist( ActiveRuleChange change, RuleActivatorContext context, DbSession dbSession) { ActiveRuleDao dao = db.activeRuleDao(); ActiveRuleDto activeRule = null; if (change.getType() == ActiveRuleChange.Type.ACTIVATED) { activeRule = ActiveRuleDto.createFor(context.profile(), context.rule()); activeRule.setSeverity(change.getSeverity()); if (change.getInheritance() != null) { activeRule.setInheritance(change.getInheritance().name()); } dao.insert(dbSession, activeRule); for (Map.Entry<String, String> param : change.getParameters().entrySet()) { if (param.getValue() != null) { ActiveRuleParamDto paramDto = ActiveRuleParamDto.createFor(context.ruleParamsByKeys().get(param.getKey())); paramDto.setValue(param.getValue()); dao.addParam(dbSession, activeRule, paramDto); } } } else if (change.getType() == ActiveRuleChange.Type.DEACTIVATED) { dao.deleteByKey(dbSession, change.getKey()); } else if (change.getType() == ActiveRuleChange.Type.UPDATED) { activeRule = context.activeRule(); activeRule.setSeverity(change.getSeverity()); if (change.getInheritance() != null) { activeRule.setInheritance(change.getInheritance().name()); } dao.update(dbSession, activeRule); for (Map.Entry<String, String> param : change.getParameters().entrySet()) { ActiveRuleParamDto activeRuleParamDto = context.activeRuleParamsAsMap().get(param.getKey()); if (activeRuleParamDto == null) { // did not exist if (param.getValue() != null) { activeRuleParamDto = ActiveRuleParamDto.createFor(context.ruleParamsByKeys().get(param.getKey())); activeRuleParamDto.setValue(param.getValue()); dao.addParam(dbSession, activeRule, activeRuleParamDto); } } else { if (param.getValue() != null) { activeRuleParamDto.setValue(param.getValue()); dao.updateParam(dbSession, activeRule, activeRuleParamDto); } else { dao.deleteParam(dbSession, activeRule, activeRuleParamDto); } } } } return activeRule; }
/** Does not commit */ private void removeParent(DbSession dbSession, QualityProfileDto profileDto) { if (profileDto.getParent() != null) { profileDto.setParent(null); db.qualityProfileDao().update(dbSession, profileDto); for (ActiveRuleDto activeRule : db.activeRuleDao().findByProfileKey(dbSession, profileDto.getKey())) { if (ActiveRuleDto.INHERITED.equals(activeRule.getInheritance())) { deactivate(dbSession, activeRule.getKey(), true); } else if (ActiveRuleDto.OVERRIDES.equals(activeRule.getInheritance())) { activeRule.setInheritance(null); db.activeRuleDao().update(dbSession, activeRule); } } } }