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\"" + " }" + "}");
}
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\"" + " }" + "}");
}
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\"" + " }" + "}");
}
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));
}
}
Aggregations