Package org.sonar.server.rule.index

Examples of org.sonar.server.rule.index.RuleQuery


    // 1. assert getBy for removed
    assertThat(index.getByKey(RuleTesting.XOO_X2)).isNotNull();

    // 2. assert find does not get REMOVED
    List<Rule> rules = index.search(new RuleQuery(), new QueryContext()).getHits();
    assertThat(rules).hasSize(1);
    assertThat(rules.get(0).key()).isEqualTo(RuleTesting.XOO_X1);
  }
View Full Code Here


    assertThat(rules.get(0).getKey()).isEqualTo(RuleKey.of("xoo", "x1"));
    List<RuleParamDto> ruleParams = db.ruleDao().findAllRuleParams(dbSession);
    assertThat(ruleParams).hasSize(2);

    // verify es
    Result<Rule> searchResult = ruleIndex.search(new RuleQuery(), new QueryContext());
    assertThat(searchResult.getTotal()).isEqualTo(1);
    assertThat(searchResult.getHits()).hasSize(1);
    Rule rule = ruleIndex.getByKey(RuleKey.of("xoo", "x1"));
    assertThat(rule.severity()).isEqualTo(Severity.MINOR);
    assertThat(rule.name()).isEqualTo("x1 name");
View Full Code Here

    // clear ES but keep db
    TESTER.clearIndexes();
    register(rules);

    // verify that rules are indexed
    Result<Rule> searchResult = ruleIndex.search(new RuleQuery(), new QueryContext());
    searchResult = ruleIndex.search(new RuleQuery().setKey("xoo:x1"), new QueryContext());
    assertThat(searchResult.getTotal()).isEqualTo(1);
    assertThat(searchResult.getHits()).hasSize(1);
    assertThat(searchResult.getHits().get(0).key()).isEqualTo(RuleKey.of("xoo", "x1"));
  }
View Full Code Here

    assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).isEmpty();
    assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(0);

    // 2. Assert ActiveRule with BLOCKER severity
    assertThat(tester.get(RuleIndex.class).search(
      new RuleQuery().setSeverities(ImmutableSet.of("BLOCKER")),
      new QueryContext()).getHits()).hasSize(2);

    // 1. Activate Rule with query returning 2 hits
    WsTester.TestRequest request = wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
    request.setParam(BulkRuleActivationActions.PROFILE_KEY, profile.getKey().toString());
View Full Code Here

    }
    return rule;
  }

  public RuleQuery newRuleQuery() {
    return new RuleQuery();
  }
View Full Code Here

    return index.get(ActiveRuleIndex.class).getStatsByProfileKeys(keys);
  }

  public long countDeprecatedActiveRulesByProfile(String key) {
    return index.get(RuleIndex.class).search(
      new RuleQuery()
        .setQProfileKey(key)
        .setActivation(true)
        .setStatuses(Lists.newArrayList(RuleStatus.DEPRECATED)),
      new QueryContext().setLimit(0)).getTotal();
  }
View Full Code Here

    }
    json.endArray();
  }

  private void appendManualRules(JsonWriter json) {
    Result<Rule> result = ruleService.search(new RuleQuery().setRepositories(newArrayList(RuleDoc.MANUAL_REPOSITORY)), new QueryContext().setMaxLimit());
    if (result != null && !result.getHits().isEmpty()) {
      List<Rule> manualRules = result.getHits();
      json.name("manual_rules").beginArray();
      for (Rule manualRule : manualRules) {
        json.beginObject()
View Full Code Here

    return apiRule;
  }

  private RuleQuery toQuery(org.sonar.api.rules.RuleQuery apiQuery) {
    RuleQuery query = new RuleQuery();
    if (apiQuery.getConfigKey() != null) {
      query.setInternalKey(apiQuery.getConfigKey());
    }
    if (apiQuery.getKey() != null) {
      query.setRuleKey(apiQuery.getKey());
    }
    if (apiQuery.getRepositoryKey() != null) {
      query.setRepositories(ImmutableList.of(apiQuery.getRepositoryKey()));
    }
    return query;
  }
View Full Code Here

      .setDefaultValue(true);
  }

  @Override
  public void handle(Request request, Response response) {
    RuleQuery query = createRuleQuery(ruleService.newRuleQuery(), request);
    SearchOptions searchOptions = SearchOptions.create(request);
    QueryContext queryContext = mapping.newQueryOptions(searchOptions);
    Boolean facets = request.paramAsBoolean(PARAM_FACETS);
    if (facets != null && facets) {
      queryContext.addFacets(Arrays.asList("languages", "repositories", "tags"));
View Full Code Here

  /**
   * Used in SQALE
   * If 'pageSize' params is set no -1, all rules are returned (using scrolling)
   */
  public PagedResult<Rule> find(Map<String, Object> params) {
    RuleQuery query = new RuleQuery();
    query.setQueryText(Strings.emptyToNull((String) params.get("searchQuery")));
    query.setKey(Strings.emptyToNull((String) params.get("key")));
    query.setLanguages(RubyUtils.toStrings(params.get("languages")));
    query.setRepositories(RubyUtils.toStrings(params.get("repositories")));
    query.setSeverities(RubyUtils.toStrings(params.get("severities")));
    query.setStatuses(RubyUtils.toEnums(params.get("statuses"), RuleStatus.class));
    query.setTags(RubyUtils.toStrings(params.get("tags")));
    query.setDebtCharacteristics(RubyUtils.toStrings(params.get("debtCharacteristics")));
    query.setHasDebtCharacteristic(RubyUtils.toBoolean(params.get("hasDebtCharacteristic")));
    query.setSortField(RuleNormalizer.RuleField.NAME);

    QueryContext options = new QueryContext();
    Integer pageSize = RubyUtils.toInteger(params.get("pageSize"));
    int size = pageSize != null ? pageSize : 50;
    if (size > -1) {
View Full Code Here

TOP

Related Classes of org.sonar.server.rule.index.RuleQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.