use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class RuleActivator method cascadeActivation.
private List<ActiveRuleChange> cascadeActivation(DbSession session, RuleActivation activation, String profileKey) {
List<ActiveRuleChange> changes = Lists.newArrayList();
// get all inherited profiles
List<QualityProfileDto> children = db.qualityProfileDao().selectChildren(session, profileKey);
for (QualityProfileDto child : children) {
RuleActivation childActivation = new RuleActivation(activation).setCascade(true);
changes.addAll(activate(session, childActivation, child.getKey()));
}
return changes;
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class RuleActivator method setParent.
public List<ActiveRuleChange> setParent(DbSession dbSession, String profileKey, @Nullable String parentKey) {
QualityProfileDto profile = db.qualityProfileDao().selectOrFailByKey(dbSession, profileKey);
List<ActiveRuleChange> changes = new ArrayList<>();
if (parentKey == null) {
// unset if parent is defined, else nothing to do
changes.addAll(removeParent(dbSession, profile));
} else if (profile.getParentKee() == null || !parentKey.equals(profile.getParentKee())) {
QualityProfileDto parentProfile = db.qualityProfileDao().selectOrFailByKey(dbSession, parentKey);
checkRequest(!isDescendant(dbSession, profile, parentProfile), "Descendant profile '%s' can not be selected as parent of '%s'", parentKey, profileKey);
changes.addAll(removeParent(dbSession, profile));
// set new parent
profile.setParentKee(parentKey);
db.qualityProfileDao().update(dbSession, profile);
for (ActiveRuleDto parentActiveRule : db.activeRuleDao().selectByProfileKey(dbSession, parentKey)) {
try {
RuleActivation activation = new RuleActivation(parentActiveRule.getKey().ruleKey());
changes.addAll(activate(dbSession, activation, profileKey));
} catch (BadRequestException e) {
// for example because rule status is REMOVED
// TODO return errors
}
}
}
dbSession.commit();
activeRuleIndexer.index(changes);
return changes;
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class DeleteAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
qProfileWsSupport.checkQProfileAdminPermission();
try (DbSession dbSession = dbClient.openSession(false)) {
QualityProfileDto profile = profileFactory.find(dbSession, QProfileRef.from(request));
profileFactory.delete(dbSession, profile.getKey(), false);
dbSession.commit();
}
response.noContent();
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class ExportAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String name = request.param(PARAM_PROFILE_NAME);
String language = request.mandatoryParam(PARAM_LANGUAGE);
String exporterKey = exporters.exportersForLanguage(language).isEmpty() ? null : request.param(PARAM_FORMAT);
QualityProfileDto profile = getProfile(name, language);
writeResponse(profile, exporterKey, response);
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class RuleQueryFactory method createRuleQuery.
/**
* Create a {@link RuleQuery} from a {@link Request}.
* When a profile key is set, the language of the profile is automatically set in the query
*/
public RuleQuery createRuleQuery(Request request) {
RuleQuery ruleQuery = createRuleQuery(new RuleQuery(), request);
String qProfileKey = ruleQuery.getQProfileKey();
if (qProfileKey != null) {
QualityProfileDto qProfile = getProfileByKey(qProfileKey);
if (qProfile != null) {
ruleQuery.setLanguages(ImmutableList.of(qProfile.getLanguage()));
}
}
return ruleQuery;
}
Aggregations