use of org.sonar.db.qualityprofile.DefaultQProfileDto in project sonarqube by SonarSource.
the class RegisterQualityProfiles method ensureBuiltInDefaultQPContainsRules.
/**
* This method ensure that if a default built-in quality profile does not have any active rules but another built-in one for the same language
* does have active rules, the last one will be the default one.
*
* @see <a href="https://jira.sonarsource.com/browse/SONAR-10363">SONAR-10363</a>
*/
private void ensureBuiltInDefaultQPContainsRules(DbSession dbSession) {
Map<String, RulesProfileDto> rulesProfilesByLanguage = dbClient.qualityProfileDao().selectBuiltInRuleProfilesWithActiveRules(dbSession).stream().collect(toMap(RulesProfileDto::getLanguage, Function.identity(), (oldValue, newValue) -> oldValue));
dbClient.qualityProfileDao().selectDefaultBuiltInProfilesWithoutActiveRules(dbSession, rulesProfilesByLanguage.keySet()).forEach(qp -> {
RulesProfileDto rulesProfile = rulesProfilesByLanguage.get(qp.getLanguage());
if (rulesProfile == null) {
return;
}
QProfileDto qualityProfile = dbClient.qualityProfileDao().selectByRuleProfileUuid(dbSession, rulesProfile.getUuid());
if (qualityProfile == null) {
return;
}
Set<String> uuids = dbClient.defaultQProfileDao().selectExistingQProfileUuids(dbSession, Collections.singleton(qp.getKee()));
dbClient.defaultQProfileDao().deleteByQProfileUuids(dbSession, uuids);
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, new DefaultQProfileDto().setQProfileUuid(qualityProfile.getKee()).setLanguage(qp.getLanguage()));
LOGGER.info("Default built-in quality profile for language [{}] has been updated from [{}] to [{}] since previous default does not have active rules.", qp.getLanguage(), qp.getName(), rulesProfile.getName());
});
dbSession.commit();
}
use of org.sonar.db.qualityprofile.DefaultQProfileDto in project sonarqube by SonarSource.
the class BuiltInQProfileInsertImpl method createDefaultAndOrgQProfiles.
private void createDefaultAndOrgQProfiles(DbSession batchDbSession, BuiltInQProfile builtIn, RulesProfileDto rulesProfileDto) {
Optional<String> qProfileUuid = dbClient.defaultQProfileDao().selectDefaultQProfileUuid(batchDbSession, builtIn.getLanguage());
OrgQProfileDto dto = new OrgQProfileDto().setRulesProfileUuid(rulesProfileDto.getUuid()).setUuid(uuidFactory.create());
if (builtIn.isDefault() && qProfileUuid.isEmpty()) {
DefaultQProfileDto defaultQProfileDto = new DefaultQProfileDto().setQProfileUuid(dto.getUuid()).setLanguage(builtIn.getLanguage());
dbClient.defaultQProfileDao().insert(batchDbSession, defaultQProfileDto);
}
dbClient.qualityProfileDao().insert(batchDbSession, dto);
}
Aggregations