import org.sonar.jpa.dao.BaseDao;
import org.sonar.jpa.dao.RulesDao;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.util.List;
this.dryRunCache = dryRunCache;
}
+ public ProfilesManager(DatabaseSession session, PreviewCache dryRunCache) {
+ super(session);
+ this.dryRunCache = dryRunCache;
+ }
+
public int copyProfile(int profileId, String newProfileName) {
RulesProfile profile = getSession().getSingleResult(RulesProfile.class, "id", profileId);
RulesProfile toImport = (RulesProfile) profile.clone();
/**
* Rule param was changed
*/
- public RuleInheritanceActions ruleParamChanged(int profileId, int activeRuleId, String paramKey, String oldValue, String newValue, String userName) {
+ public RuleInheritanceActions ruleParamChanged(int profileId, int activeRuleId, String paramKey, @Nullable String oldValue, @Nullable String newValue, String userName) {
ActiveRule activeRule = getSession().getEntity(ActiveRule.class, activeRuleId);
RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId);
getSession().removeWithoutFlush(activeRule);
}
- RulesProfile getProfile(String language, String name) {
+ @CheckForNull
+ RulesProfile getProfile(String language, @Nullable String name) {
return getSession().getSingleResult(RulesProfile.class,
"language", language,
"name", name);
}
+ @CheckForNull
RulesProfile getParentProfile(RulesProfile profile) {
if (profile.getParentName() == null) {
return null;
import org.elasticsearch.common.base.Predicate;
import org.elasticsearch.common.collect.Iterables;
import org.sonar.api.ServerComponent;
-import org.sonar.api.server.rule.RuleParamType;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RulePriority;
+import org.sonar.api.server.rule.RuleParamType;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.MyBatis;
activeRuleDao.insert(activeRuleParam, session);
}
session.commit();
- ProfilesManager.RuleInheritanceActions actions = profilesManager.activated(profileId, activeRule.getId(), userSession.name());
+ ProfilesManager.RuleInheritanceActions actions = profilesManager.activated(profileId, activeRule.getId(), getLoggedName(userSession));
reindexInheritanceResult(actions, session);
return activeRule;
}
private boolean deactivateRule(ActiveRuleDto activeRule, UserSession userSession, SqlSession session) {
if (activeRule.getInheritance() == null) {
- ProfilesManager.RuleInheritanceActions actions = profilesManager.deactivated(activeRule.getProfileId(), activeRule.getId(), userSession.name());
+ ProfilesManager.RuleInheritanceActions actions = profilesManager.deactivated(activeRule.getProfileId(), activeRule.getId(), getLoggedName(userSession));
activeRuleDao.deleteParameters(activeRule.getId(), session);
activeRuleDao.delete(activeRule.getId(), session);
activeRuleDao.insert(activeRuleParam, session);
session.commit();
- ProfilesManager.RuleInheritanceActions actions = profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), key, null, value, userSession.name());
+ ProfilesManager.RuleInheritanceActions actions = profilesManager.ruleParamChanged(
+ activeRule.getProfileId(), activeRule.getId(), key, null, value, getLoggedName(userSession));
reindexInheritanceResult(actions, session);
}
} else {
activeRuleDao.deleteParameter(param.getId(), session);
session.commit();
- actions.add(profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), key, param.getValue(), null, userSession.name()));
+ actions.add(profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), key, param.getValue(), null, getLoggedName(userSession)));
}
paramKeys.add(key);
}
activeRuleDao.insert(activeRuleParam, session);
session.commit();
newParams.add(activeRuleParam);
- actions.add(profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), parentParam.getKey(), null, parentParam.getValue(), userSession.name()));
+ actions.add(profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), parentParam.getKey(), null, parentParam.getValue(), getLoggedName(userSession)));
}
}
return newParams;
activeRuleDao.update(activeRule, session);
session.commit();
actions.add(profilesManager.ruleSeverityChanged(activeRule.getProfileId(), activeRule.getId(),
- RulePriority.valueOf(getSeverityFromOrdinal(oldSeverity)), RulePriority.valueOf(getSeverityFromOrdinal(newSeverity)), userSession.name()));
+ RulePriority.valueOf(getSeverityFromOrdinal(oldSeverity)), RulePriority.valueOf(getSeverityFromOrdinal(newSeverity)), getLoggedName(userSession)));
}
}
ProfilesManager.RuleInheritanceActions actions = new ProfilesManager.RuleInheritanceActions();
for (ActiveRuleParamDto activeRuleParam : params) {
actions.add(profilesManager.ruleParamChanged(activeRule.getProfileId(), activeRule.getId(), activeRuleParam.getKey(), activeRuleParam.getValue(),
- null, userSession.name()));
+ null, getLoggedName(userSession)));
}
reindexInheritanceResult(actions, session);
}
private void notifySeverityChanged(ActiveRuleDto activeRule, String newSeverity, String oldSeverity, SqlSession session, UserSession userSession) {
ProfilesManager.RuleInheritanceActions actions = profilesManager.ruleSeverityChanged(activeRule.getProfileId(), activeRule.getId(),
RulePriority.valueOf(oldSeverity), RulePriority.valueOf(newSeverity),
- userSession.name());
+ getLoggedName(userSession));
reindexInheritanceResult(actions, session);
}