Search in sources :

Example 1 with FOO_TYPE

use of org.sonar.server.permission.index.FooIndexDefinition.FOO_TYPE in project sonarqube by SonarSource.

the class FooIndex method hasAccessToProject.

public boolean hasAccessToProject(String projectUuid) {
    SearchHits hits = esClient.prepareSearch(FOO_INDEX).setTypes(FOO_TYPE).setQuery(QueryBuilders.boolQuery().must(QueryBuilders.termQuery(FooIndexDefinition.FIELD_PROJECT_UUID, projectUuid)).filter(authorizationTypeSupport.createQueryFilter())).get().getHits();
    List<String> names = Arrays.stream(hits.hits()).map(h -> h.getSource().get(FooIndexDefinition.FIELD_NAME).toString()).collect(Collectors.toList());
    return names.size() == 2 && names.contains("bar") && names.contains("baz");
}
Also used : Arrays(java.util.Arrays) List(java.util.List) SearchHits(org.elasticsearch.search.SearchHits) FOO_INDEX(org.sonar.server.permission.index.FooIndexDefinition.FOO_INDEX) Collectors(org.sonar.core.util.stream.Collectors) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) FOO_TYPE(org.sonar.server.permission.index.FooIndexDefinition.FOO_TYPE) EsClient(org.sonar.server.es.EsClient) SearchHits(org.elasticsearch.search.SearchHits)

Aggregations

Arrays (java.util.Arrays)1 List (java.util.List)1 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)1 SearchHits (org.elasticsearch.search.SearchHits)1 Collectors (org.sonar.core.util.stream.Collectors)1 EsClient (org.sonar.server.es.EsClient)1 FOO_INDEX (org.sonar.server.permission.index.FooIndexDefinition.FOO_INDEX)1 FOO_TYPE (org.sonar.server.permission.index.FooIndexDefinition.FOO_TYPE)1