use of org.sonar.server.rule.index.RuleQuery 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;
}
use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
SearchWsRequest searchWsRequest = toSearchWsRequest(request);
SearchOptions context = buildSearchOptions(searchWsRequest);
RuleQuery query = ruleQueryFactory.createRuleQuery(request);
SearchResult searchResult = doSearch(dbSession, query, context);
SearchResponse responseBuilder = buildResponse(dbSession, searchWsRequest, context, searchResult, query);
writeProtobuf(responseBuilder, request, response);
}
}
use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method bulk_activation.
@Test
public void bulk_activation() {
// Generate more rules than the search's max limit
int bulkSize = SearchOptions.MAX_LIMIT + 10;
for (int i = 0; i < bulkSize; i++) {
db.ruleDao().insert(dbSession, newDto(RuleKey.of("bulk", "r_" + i)).setLanguage("xoo"));
}
dbSession.commit();
ruleIndexer.index();
// 0. No active rules so far (base case) and plenty rules available
verifyZeroActiveRules(XOO_P1_KEY);
assertThat(tester.get(RuleIndex.class).search(new RuleQuery().setRepositories(Arrays.asList("bulk")), new SearchOptions()).getTotal()).isEqualTo(bulkSize);
// 1. bulk activate all the rules
BulkChangeResult result = ruleActivator.bulkActivate(new RuleQuery().setRepositories(Arrays.asList("bulk")), XOO_P1_KEY, "MINOR");
// 2. assert that all activation has been commit to DB and ES
dbSession.clearCache();
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(bulkSize);
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(bulkSize);
assertThat(result.countSucceeded()).isEqualTo(bulkSize);
assertThat(result.countFailed()).isEqualTo(0);
}
use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method verifyZeroActiveRules.
private void verifyZeroActiveRules(String key) {
// verify db
dbSession.clearCache();
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().selectByProfileKey(dbSession, key);
assertThat(activeRuleDtos).isEmpty();
// verify es
assertThat(tester.get(RuleIndex.class).searchAll(new RuleQuery().setQProfileKey(key).setActivation(true))).isEmpty();
}
use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method bulk_deactivation_ignores_errors.
@Test
public void bulk_deactivation_ignores_errors() {
// activate on parent profile P1
createChildProfiles();
activate(new RuleActivation(XOO_X1), XOO_P1_KEY);
assertThat(countActiveRules(XOO_P2_KEY)).isEqualTo(1);
// bulk deactivate on child profile P2 -> not possible
BulkChangeResult result = ruleActivator.bulkDeactivate(new RuleQuery().setActivation(true).setQProfileKey(XOO_P2_KEY), XOO_P2_KEY);
dbSession.clearCache();
assertThat(countActiveRules(XOO_P2_KEY)).isEqualTo(1);
assertThat(result.countFailed()).isEqualTo(1);
assertThat(result.countSucceeded()).isEqualTo(0);
assertThat(result.getChanges()).hasSize(0);
}
Aggregations