@Test public void constructSameQueryForSameFilters() { SearchFilter a1 = new SearchFilter("a", "1"); SearchFilter a2 = new SearchFilter("a", "2"); SearchFilter b1 = new SearchFilter("b", "1"); SearchFilter b2 = new SearchFilter("b", "2"); SearchFilter c1 = new SearchFilter("c", "1"); List<SearchFilter> forwards = newArrayList(a1, a2, b1, b2, c1); List<SearchFilter> backward = newArrayList(c1, b2, b1, a2, a1); List<SearchFilter> mixed = newArrayList(a1, c1 ,b1, b2, a2); String forwardQuery = underTest.buildQuery(forwards).toString(); String backwardQuery = underTest.buildQuery(backward).toString(); String mixedQuery = underTest.buildQuery(mixed).toString(); assertThat(forwardQuery.equals(backwardQuery), is(true)); assertThat(forwardQuery.equals(mixedQuery), is(true)); }
public QueryBuilder buildQuery(final Collection<SearchFilter> searchFilters) { BoolQueryBuilder query = QueryBuilders.boolQuery(); searchFilters.stream() .filter(searchFilter -> !isBlank(searchFilter.getValue())) .sorted(comparing(SearchFilter::getProperty).thenComparing(SearchFilter::getValue)) .forEach(searchFilter -> { SearchContribution searchContribution = searchContributions .getOrDefault(searchFilter.getProperty(), defaultSearchContribution); searchContribution.contribute(query, searchFilter.getProperty(), searchFilter.getValue()); }); log.debug("Query: {}", query); return query; }
SearchUtils extends ComponentSupport { public QueryBuilder buildQuery(final Collection<SearchFilter> searchFilters) { BoolQueryBuilder query = QueryBuilders.boolQuery(); searchFilters.stream() .filter(searchFilter -> !isBlank(searchFilter.getValue())) .sorted(comparing(SearchFilter::getProperty).thenComparing(SearchFilter::getValue)) .forEach(searchFilter -> { SearchContribution searchContribution = searchContributions .getOrDefault(searchFilter.getProperty(), defaultSearchContribution); searchContribution.contribute(query, searchFilter.getProperty(), searchFilter.getValue()); }); log.debug("Query: {}", query); return query; } }
SearchUtils extends ComponentSupport { public QueryBuilder buildQuery(final Collection<SearchFilter> searchFilters) { BoolQueryBuilder query = QueryBuilders.boolQuery(); searchFilters.stream() .filter(searchFilter -> !isBlank(searchFilter.getValue())) .sorted(comparing(SearchFilter::getProperty).thenComparing(SearchFilter::getValue)) .forEach(searchFilter -> { SearchContribution searchContribution = searchContributions .getOrDefault(searchFilter.getProperty(), defaultSearchContribution); searchContribution.contribute(query, searchFilter.getProperty(), searchFilter.getValue()); }); log.debug("Query: {}", query); return query; } @Inject  SearchUtils(final RepositoryManagerRESTAdapter repoAdapter,
                     final Map<String, SearchMappings> searchMappings,
                     final Map<String, SearchContribution> searchContributions); }
SearchUtils extends ComponentSupport { public QueryBuilder buildQuery(final Collection<SearchFilter> searchFilters) { BoolQueryBuilder query = QueryBuilders.boolQuery(); searchFilters.stream() .filter(searchFilter -> !isBlank(searchFilter.getValue())) .sorted(comparing(SearchFilter::getProperty).thenComparing(SearchFilter::getValue)) .forEach(searchFilter -> { SearchContribution searchContribution = searchContributions .getOrDefault(searchFilter.getProperty(), defaultSearchContribution); searchContribution.contribute(query, searchFilter.getProperty(), searchFilter.getValue()); }); log.debug("Query: {}", query); return query; } @Inject  SearchUtils(final RepositoryManagerRESTAdapter repoAdapter,
                     final Map<String, SearchMappings> searchMappings,
                     final Map<String, SearchContribution> searchContributions); Map<String, String> getSearchParameters(); Map<String, String> getAssetSearchParameters(); Repository getRepository(final String repository); QueryBuilder buildQuery(final Collection<SearchFilter> searchFilters); QueryBuilder buildQuery(final UriInfo uriInfo); QueryBuilder buildQuery(final UriInfo uriInfo, final List<String> parameters); boolean isAssetSearchParam(final String assetSearchParam); boolean isFullAssetAttributeName(final String assetSearchParam); String getFullAssetAttributeName(final String key); List<SortBuilder> getSortBuilders(final String sort, final String direction); List<SortBuilder> getSortBuilders(final String sort, final String direction, boolean allowAnySort); }
SearchUtils extends ComponentSupport { public QueryBuilder buildQuery(final Collection<SearchFilter> searchFilters) { BoolQueryBuilder query = QueryBuilders.boolQuery(); searchFilters.stream() .filter(searchFilter -> !isBlank(searchFilter.getValue())) .sorted(comparing(SearchFilter::getProperty).thenComparing(SearchFilter::getValue)) .forEach(searchFilter -> { SearchContribution searchContribution = searchContributions .getOrDefault(searchFilter.getProperty(), defaultSearchContribution); searchContribution.contribute(query, searchFilter.getProperty(), searchFilter.getValue()); }); log.debug("Query: {}", query); return query; } @Inject  SearchUtils(final RepositoryManagerRESTAdapter repoAdapter,
                     final Map<String, SearchMappings> searchMappings,
                     final Map<String, SearchContribution> searchContributions); Map<String, String> getSearchParameters(); Map<String, String> getAssetSearchParameters(); Repository getRepository(final String repository); QueryBuilder buildQuery(final Collection<SearchFilter> searchFilters); QueryBuilder buildQuery(final UriInfo uriInfo); QueryBuilder buildQuery(final UriInfo uriInfo, final List<String> parameters); boolean isAssetSearchParam(final String assetSearchParam); boolean isFullAssetAttributeName(final String assetSearchParam); String getFullAssetAttributeName(final String key); List<SortBuilder> getSortBuilders(final String sort, final String direction); List<SortBuilder> getSortBuilders(final String sort, final String direction, boolean allowAnySort); static final String CONTINUATION_TOKEN; static final String SORT_FIELD; static final String SORT_DIRECTION; }