}
}
- public void delete(Integer id) {
+ public void delete(int id) {
SqlSession session = mybatis.openSession();
try {
session.getMapper(QualityProfileMapper.class).delete(id);
}
}
- public List<QualityProfileDto> selectByProject(Long projectId, String propKeyPrefix) {
+ public List<QualityProfileDto> selectByProject(long projectId, String propKeyPrefix) {
SqlSession session = mybatis.openSession();
try {
return session.getMapper(QualityProfileMapper.class).selectByProject(projectId, propKeyPrefix);
}
@CheckForNull
- public QualityProfileDto selectById(Integer id, SqlSession session) {
+ public QualityProfileDto selectById(int id, SqlSession session) {
return session.getMapper(QualityProfileMapper.class).selectById(id);
}
@CheckForNull
- public QualityProfileDto selectById(Integer id) {
+ public QualityProfileDto selectById(int id) {
SqlSession session = mybatis.openSession();
try {
return selectById(id, session);
}
@CheckForNull
- public QualityProfileDto selectParent(Integer childId, SqlSession session) {
+ public QualityProfileDto selectParent(int childId, SqlSession session) {
return session.getMapper(QualityProfileMapper.class).selectParent(childId);
}
@CheckForNull
- public QualityProfileDto selectParent(Integer childId) {
+ public QualityProfileDto selectParent(int childId) {
SqlSession session = mybatis.openSession();
try {
return selectParent(childId, session);
import org.sonar.core.rule.RuleParamDto;
import org.sonar.server.configuration.ProfilesManager;
import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.rule.RuleRegistry;
import org.sonar.server.user.UserSession;
validatePermission(userSession);
SqlSession session = myBatis.openSession();
try {
- ActiveRuleDto activeRule = findActiveRule(profileId, ruleId, session);
+ ActiveRuleDto activeRule = findActiveRuleNotNull(profileId, ruleId, session);
return deactivateRule(activeRule, userSession, session);
} finally {
MyBatis.closeQuietly(session);
return activeRuleDao.selectByProfileAndRule(profileId, ruleId, session);
}
+ private ActiveRuleDto findActiveRuleNotNull(int profileId, int ruleId, SqlSession session) {
+ ActiveRuleDto activeRule = findActiveRule(profileId, ruleId, session);
+ QProfileValidations.checkActiveRuleIsNotNull(activeRule);
+ return activeRule;
+ }
+
private ActiveRuleDto findActiveRuleNotNull(int activeRuleId, SqlSession session) {
ActiveRuleDto activeRule = activeRuleDao.selectById(activeRuleId, session);
- if (activeRule == null) {
- throw new NotFoundException("This active rule does not exists.");
- }
+ QProfileValidations.checkActiveRuleIsNotNull(activeRule);
return activeRule;
}
@CheckForNull
public QProfile parent(QProfile profile) {
- if (profile.parent() != null) {
- QualityProfileDto parent = findQualityProfile(profile.parent(), profile.language());
- if (parent != null) {
- return QProfile.from(parent);
+ String parent = profile.parent();
+ if (parent != null) {
+ QualityProfileDto parentDto = findQualityProfile(parent, profile.language());
+ if (parentDto != null) {
+ return QProfile.from(parentDto);
}
}
return null;
package org.sonar.server.qualityprofile;
+import org.sonar.core.qualityprofile.db.ActiveRuleDto;
import org.sonar.core.qualityprofile.db.QualityProfileDto;
import org.sonar.core.rule.RuleDto;
import org.sonar.server.exceptions.NotFoundException;
+import javax.annotation.Nullable;
+
public class QProfileValidations {
- public static void checkProfileIsNotNull(QProfile profile) {
+ private static final String QUALITY_PROFILE_DOES_NOT_EXISTS_MESSAGE = "This quality profile does not exists.";
+
+ public static void checkProfileIsNotNull(@Nullable QProfile profile) {
if (profile == null) {
- throw new NotFoundException("This quality profile does not exists.");
+ throw new NotFoundException(QUALITY_PROFILE_DOES_NOT_EXISTS_MESSAGE);
}
}
- public static void checkProfileIsNotNull(QualityProfileDto profile) {
+ public static void checkProfileIsNotNull(@Nullable QualityProfileDto profile) {
if (profile == null) {
- throw new NotFoundException("This quality profile does not exists.");
+ throw new NotFoundException(QUALITY_PROFILE_DOES_NOT_EXISTS_MESSAGE);
}
}
- public static void checkRuleIsNotNull(QProfileRule rule) {
+ public static void checkRuleIsNotNull(@Nullable RuleDto rule) {
if (rule == null) {
throw new NotFoundException("This rule does not exists.");
}
}
- public static void checkRuleIsNotNull(RuleDto rule) {
- if (rule == null) {
- throw new NotFoundException("This rule does not exists.");
+ public static void checkActiveRuleIsNotNull(@Nullable ActiveRuleDto activeRule) {
+ if (activeRule == null) {
+ throw new NotFoundException("This active rule does not exists.");
}
}
}