Search in sources :

Example 1 with HasParentQueryBuilder

use of org.elasticsearch.join.query.HasParentQueryBuilder in project sonarqube by SonarSource.

the class WebAuthorizationTypeSupportTest method createQueryFilter_sets_filter_on_anyone_and_user_id_and_group_ids_if_user_is_logged_in_and_has_groups.

@Test
public void createQueryFilter_sets_filter_on_anyone_and_user_id_and_group_ids_if_user_is_logged_in_and_has_groups() {
    GroupDto group1 = GroupTesting.newGroupDto().setUuid("10");
    GroupDto group2 = GroupTesting.newGroupDto().setUuid("11");
    UserDto userDto = UserTesting.newUserDto();
    userSession.logIn(userDto).setGroups(group1, group2);
    HasParentQueryBuilder filter = (HasParentQueryBuilder) underTest.createQueryFilter();
    assertJson(filter.toString()).isSimilarTo("{" + "  \"has_parent\": {" + "    \"query\": {" + "      \"bool\": {" + "        \"filter\": [{" + "          \"bool\": {" + "            \"should\": [" + "              {" + "                \"term\": {" + "                  \"auth_allowAnyone\": {\"value\": true}" + "                }" + "              }," + "              {" + "                \"term\": {" + "                  \"auth_userIds\": {\"value\": \"" + userDto.getUuid() + "\"}" + "                }" + "              }," + "              {" + "                \"term\": {" + "                  \"auth_groupIds\": {\"value\": \"10\"}" + "                }" + "              }," + "              {" + "                \"term\": {" + "                  \"auth_groupIds\": {\"value\": \"11\"}" + "                }" + "              }" + "            ]" + "          }" + "        }]" + "      }" + "    }," + "    \"parent_type\": \"auth\"" + "  }" + "}");
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) HasParentQueryBuilder(org.elasticsearch.join.query.HasParentQueryBuilder) Test(org.junit.Test)

Example 2 with HasParentQueryBuilder

use of org.elasticsearch.join.query.HasParentQueryBuilder in project sonarqube by SonarSource.

the class WebAuthorizationTypeSupportTest method createQueryFilter_sets_filter_on_anyone_and_user_id_if_user_is_logged_in_but_has_no_groups.

@Test
public void createQueryFilter_sets_filter_on_anyone_and_user_id_if_user_is_logged_in_but_has_no_groups() {
    UserDto userDto = UserTesting.newUserDto();
    userSession.logIn(userDto);
    HasParentQueryBuilder filter = (HasParentQueryBuilder) underTest.createQueryFilter();
    assertJson(filter.toString()).isSimilarTo("{" + "  \"has_parent\": {" + "    \"query\": {" + "      \"bool\": {" + "        \"filter\": [{" + "          \"bool\": {" + "            \"should\": [" + "              {" + "                \"term\": {" + "                  \"auth_allowAnyone\": {\"value\": true}" + "                }" + "              }," + "              {" + "                \"term\": {" + "                  \"auth_userIds\": {\"value\": \"" + userDto.getUuid() + "\"}" + "                }" + "              }" + "            ]" + "          }" + "        }]" + "      }" + "    }," + "    \"parent_type\": \"auth\"" + "  }" + "}");
}
Also used : UserDto(org.sonar.db.user.UserDto) HasParentQueryBuilder(org.elasticsearch.join.query.HasParentQueryBuilder) Test(org.junit.Test)

Example 3 with HasParentQueryBuilder

use of org.elasticsearch.join.query.HasParentQueryBuilder in project sonarqube by SonarSource.

the class WebAuthorizationTypeSupportTest method createQueryFilter_sets_filter_on_anyone_group_if_user_is_anonymous.

@Test
public void createQueryFilter_sets_filter_on_anyone_group_if_user_is_anonymous() {
    userSession.anonymous();
    HasParentQueryBuilder filter = (HasParentQueryBuilder) underTest.createQueryFilter();
    assertJson(filter.toString()).isSimilarTo("{" + "  \"has_parent\" : {" + "    \"query\" : {" + "      \"bool\" : {" + "        \"filter\" : [{" + "          \"bool\" : {" + "            \"should\" : [{" + "              \"term\" : {" + "                \"auth_allowAnyone\" : {\"value\": true}" + "              }" + "            }]" + "          }" + "        }]" + "      }" + "    }," + "    \"parent_type\" : \"auth\"" + "  }" + "}");
}
Also used : HasParentQueryBuilder(org.elasticsearch.join.query.HasParentQueryBuilder) Test(org.junit.Test)

Example 4 with HasParentQueryBuilder

use of org.elasticsearch.join.query.HasParentQueryBuilder in project sonarqube by SonarSource.

the class RuleIndex method addActiveSeverityFacetIfNeeded.

private static void addActiveSeverityFacetIfNeeded(RuleQuery query, SearchOptions options, Map<String, AggregationBuilder> aggregations, StickyFacetBuilder stickyFacetBuilder) {
    QProfileDto profile = query.getQProfile();
    if (options.getFacets().contains(FACET_ACTIVE_SEVERITIES) && profile != null) {
        // We are building a children aggregation on active rules
        // so the rule filter has to be used as parent filter for active rules
        // from which we remove filters that concern active rules ("activation")
        HasParentQueryBuilder ruleFilter = JoinQueryBuilders.hasParentQuery(TYPE_RULE.getType(), stickyFacetBuilder.getStickyFacetFilter("activation"), false);
        // Rebuilding the active rule filter without severities
        BoolQueryBuilder childrenFilter = boolQuery();
        addTermFilter(childrenFilter, FIELD_ACTIVE_RULE_PROFILE_UUID, profile.getRulesProfileUuid());
        RuleIndex.addTermFilter(childrenFilter, FIELD_ACTIVE_RULE_INHERITANCE, query.getInheritance());
        QueryBuilder activeRuleFilter = childrenFilter.must(ruleFilter);
        AggregationBuilder activeSeverities = JoinAggregationBuilders.children(FACET_ACTIVE_SEVERITIES + "_children", TYPE_ACTIVE_RULE.getName()).subAggregation(AggregationBuilders.filter(FACET_ACTIVE_SEVERITIES + "_filter", activeRuleFilter).subAggregation(AggregationBuilders.terms(FACET_ACTIVE_SEVERITIES).field(FIELD_ACTIVE_RULE_SEVERITY).includeExclude(new IncludeExclude(Joiner.on('|').join(Severity.ALL), null)).size(Severity.ALL.size())));
        aggregations.put(FACET_ACTIVE_SEVERITIES, AggregationBuilders.global(FACET_ACTIVE_SEVERITIES).subAggregation(activeSeverities));
    }
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) AggregationBuilder(org.elasticsearch.search.aggregations.AggregationBuilder) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude) HasParentQueryBuilder(org.elasticsearch.join.query.HasParentQueryBuilder) HasParentQueryBuilder(org.elasticsearch.join.query.HasParentQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Aggregations

HasParentQueryBuilder (org.elasticsearch.join.query.HasParentQueryBuilder)4 Test (org.junit.Test)3 UserDto (org.sonar.db.user.UserDto)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 AggregationBuilder (org.elasticsearch.search.aggregations.AggregationBuilder)1 IncludeExclude (org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude)1 TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)1 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)1 GroupDto (org.sonar.db.user.GroupDto)1