use of org.sonar.db.qualityprofile.RulesProfileDto in project sonarqube by SonarSource.
the class ActiveRuleIndexer method doIndexRuleProfiles.
private IndexingResult doIndexRuleProfiles(DbSession dbSession, Map<String, EsQueueDto> ruleProfileItems) {
IndexingResult result = new IndexingResult();
for (Map.Entry<String, EsQueueDto> entry : ruleProfileItems.entrySet()) {
String ruleProfileUUid = entry.getKey();
EsQueueDto item = entry.getValue();
IndexingResult profileResult;
RulesProfileDto profile = dbClient.qualityProfileDao().selectRuleProfile(dbSession, ruleProfileUUid);
if (profile == null) {
// profile does not exist anymore in db --> related documents must be deleted from index rules/activeRule
SearchRequest search = EsClient.prepareSearch(TYPE_ACTIVE_RULE.getMainType()).source(new SearchSourceBuilder().query(QueryBuilders.boolQuery().must(termQuery(FIELD_ACTIVE_RULE_PROFILE_UUID, ruleProfileUUid))));
profileResult = BulkIndexer.delete(esClient, TYPE_ACTIVE_RULE, search);
} else {
BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, IndexingListener.FAIL_ON_ERROR);
bulkIndexer.start();
dbClient.activeRuleDao().scrollByRuleProfileForIndexing(dbSession, ruleProfileUUid, i -> bulkIndexer.add(newIndexRequest(i)));
profileResult = bulkIndexer.stop();
}
if (profileResult.isSuccess()) {
deleteQueueDto(dbSession, item);
}
result.add(profileResult);
}
return result;
}
use of org.sonar.db.qualityprofile.RulesProfileDto in project sonarqube by SonarSource.
the class RegisterQualityProfilesTest method insertRulesProfile.
private void insertRulesProfile(BuiltInQProfile builtIn) {
RulesProfileDto dto = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setLanguage(builtIn.getLanguage()).setName(builtIn.getName()));
dbClient.qualityProfileDao().insert(db.getSession(), dto);
db.commit();
}
use of org.sonar.db.qualityprofile.RulesProfileDto in project sonarqube by SonarSource.
the class RegisterQualityProfilesTest method update_built_in_profile_if_it_already_exists.
@Test
public void update_built_in_profile_if_it_already_exists() {
RulesProfileDto ruleProfile = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setName("Sonar way").setLanguage(FOO_LANGUAGE.getKey()));
db.getDbClient().qualityProfileDao().insert(db.getSession(), ruleProfile);
db.commit();
BuiltInQProfile builtIn = builtInQProfileRepositoryRule.add(FOO_LANGUAGE, ruleProfile.getName(), false);
builtInQProfileRepositoryRule.initialize();
underTest.start();
assertThat(insert.callLogs).isEmpty();
assertThat(update.callLogs).containsExactly(builtIn);
assertThat(logTester.logs(LoggerLevel.INFO)).contains("Update profile foo/Sonar way");
}
use of org.sonar.db.qualityprofile.RulesProfileDto in project sonarqube by SonarSource.
the class RegisterQualityProfilesTest method update_default_built_in_quality_profile.
@Test
public void update_default_built_in_quality_profile() {
RulesProfileDto ruleProfileWithoutRule = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setName("Sonar way").setLanguage(FOO_LANGUAGE.getKey()));
RulesProfileDto ruleProfileWithOneRule = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setName("Sonar way 2").setLanguage(FOO_LANGUAGE.getKey()));
QProfileDto qProfileWithoutRule = newQualityProfileDto().setIsBuiltIn(true).setLanguage(FOO_LANGUAGE.getKey()).setRulesProfileUuid(ruleProfileWithoutRule.getUuid());
QProfileDto qProfileWithOneRule = newQualityProfileDto().setIsBuiltIn(true).setLanguage(FOO_LANGUAGE.getKey()).setRulesProfileUuid(ruleProfileWithOneRule.getUuid());
db.qualityProfiles().insert(qProfileWithoutRule, qProfileWithOneRule);
db.qualityProfiles().setAsDefault(qProfileWithoutRule);
RuleDefinitionDto ruleDefinition = db.rules().insert();
db.qualityProfiles().activateRule(qProfileWithOneRule, ruleDefinition);
db.commit();
builtInQProfileRepositoryRule.add(FOO_LANGUAGE, ruleProfileWithoutRule.getName(), true);
builtInQProfileRepositoryRule.add(FOO_LANGUAGE, ruleProfileWithOneRule.getName(), false);
builtInQProfileRepositoryRule.initialize();
underTest.start();
logTester.logs(LoggerLevel.INFO).contains(format("Default built-in quality profile for language [foo] has been updated from [%s] to [%s] since previous default does not have active rules.", qProfileWithoutRule.getName(), qProfileWithOneRule.getName()));
assertThat(selectUuidOfDefaultProfile(FOO_LANGUAGE.getKey())).isPresent().get().isEqualTo(qProfileWithOneRule.getKee());
}
use of org.sonar.db.qualityprofile.RulesProfileDto in project sonarqube by SonarSource.
the class QProfileFactoryImplTest method delete_builtin_profile_marked_as_default.
@Test
public void delete_builtin_profile_marked_as_default() {
RulesProfileDto builtInProfile = createBuiltInProfile();
QProfileDto profile = associateBuiltInProfile(builtInProfile);
db.qualityProfiles().setAsDefault(profile);
underTest.delete(dbSession, asList(profile));
verifyNoCallsActiveRuleIndexerDelete();
// remove only from org_qprofiles and default_qprofiles
assertThat(db.getDbClient().qualityProfileDao().selectAll(dbSession)).isEmpty();
assertThat(db.getDbClient().qualityProfileDao().selectDefaultProfile(dbSession, profile.getLanguage())).isNull();
assertThatRulesProfileExists(builtInProfile);
}
Aggregations