@Test public void testShouldSetCount() { FilterAttributeMetadataImpl filterAttributeMetadata = new FilterAttributeMetadataImpl(); filterAttributeMetadata.setAttributeInputType(FilterAttributeMetadataImpl.INPUT_TYPE_SELECT); filterAttributeMetadata.setAttributeCode(BLACK_ATTRIBUTE); converterUnderTest = new AggregationOptionToSearchAggregationOptionConverter(BLACK_ATTRIBUTE, filterAttributeMetadata, existingFilters); final SearchAggregationOption resultOption = converterUnderTest.apply(aggregationOption); assertThat(resultOption.getCount()).isEqualTo(BLACK_COUNT); }
@Override public SearchAggregationOption apply(final AggregationOption aggregationOption) { SearchAggregationOptionImpl searchAggregationOption = new SearchAggregationOptionImpl(); if (filterAttributeMetadata != null && FilterAttributeMetadataImpl.INPUT_TYPE_BOOLEAN.equals(filterAttributeMetadata .getAttributeInputType())) { searchAggregationOption.setDisplayLabel(("0".equalsIgnoreCase(aggregationOption.getLabel()) ? "No" : "Yes")); } else { searchAggregationOption.setDisplayLabel(aggregationOption.getLabel()); } searchAggregationOption.setCount(aggregationOption.getCount()); searchAggregationOption.setFilterValue(aggregationOption.getValue()); Map<String, String> newFilters = new HashMap<>(filters); newFilters.put(attributeCode, aggregationOption.getValue()); searchAggregationOption.setAddFilterMap(newFilters.entrySet().stream() .filter(item -> !item.getKey().equals("page")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); return searchAggregationOption; }
AggregationOptionToSearchAggregationOptionConverter implements Function<AggregationOption, SearchAggregationOption> { @Override public SearchAggregationOption apply(final AggregationOption aggregationOption) { SearchAggregationOptionImpl searchAggregationOption = new SearchAggregationOptionImpl(); if (filterAttributeMetadata != null && FilterAttributeMetadataImpl.INPUT_TYPE_BOOLEAN.equals(filterAttributeMetadata .getAttributeInputType())) { searchAggregationOption.setDisplayLabel(("0".equalsIgnoreCase(aggregationOption.getLabel()) ? "No" : "Yes")); } else { searchAggregationOption.setDisplayLabel(aggregationOption.getLabel()); } searchAggregationOption.setCount(aggregationOption.getCount()); searchAggregationOption.setFilterValue(aggregationOption.getValue()); Map<String, String> newFilters = new HashMap<>(filters); newFilters.put(attributeCode, aggregationOption.getValue()); searchAggregationOption.setAddFilterMap(newFilters.entrySet().stream() .filter(item -> !item.getKey().equals("page")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); return searchAggregationOption; } }
AggregationOptionToSearchAggregationOptionConverter implements Function<AggregationOption, SearchAggregationOption> { @Override public SearchAggregationOption apply(final AggregationOption aggregationOption) { SearchAggregationOptionImpl searchAggregationOption = new SearchAggregationOptionImpl(); if (filterAttributeMetadata != null && FilterAttributeMetadataImpl.INPUT_TYPE_BOOLEAN.equals(filterAttributeMetadata .getAttributeInputType())) { searchAggregationOption.setDisplayLabel(("0".equalsIgnoreCase(aggregationOption.getLabel()) ? "No" : "Yes")); } else { searchAggregationOption.setDisplayLabel(aggregationOption.getLabel()); } searchAggregationOption.setCount(aggregationOption.getCount()); searchAggregationOption.setFilterValue(aggregationOption.getValue()); Map<String, String> newFilters = new HashMap<>(filters); newFilters.put(attributeCode, aggregationOption.getValue()); searchAggregationOption.setAddFilterMap(newFilters.entrySet().stream() .filter(item -> !item.getKey().equals("page")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); return searchAggregationOption; } AggregationOptionToSearchAggregationOptionConverter(final String attributeCode,
                                                               final FilterAttributeMetadata filterAttributeMetadata,
                                                               final Map<String, String> filters); }
AggregationOptionToSearchAggregationOptionConverter implements Function<AggregationOption, SearchAggregationOption> { @Override public SearchAggregationOption apply(final AggregationOption aggregationOption) { SearchAggregationOptionImpl searchAggregationOption = new SearchAggregationOptionImpl(); if (filterAttributeMetadata != null && FilterAttributeMetadataImpl.INPUT_TYPE_BOOLEAN.equals(filterAttributeMetadata .getAttributeInputType())) { searchAggregationOption.setDisplayLabel(("0".equalsIgnoreCase(aggregationOption.getLabel()) ? "No" : "Yes")); } else { searchAggregationOption.setDisplayLabel(aggregationOption.getLabel()); } searchAggregationOption.setCount(aggregationOption.getCount()); searchAggregationOption.setFilterValue(aggregationOption.getValue()); Map<String, String> newFilters = new HashMap<>(filters); newFilters.put(attributeCode, aggregationOption.getValue()); searchAggregationOption.setAddFilterMap(newFilters.entrySet().stream() .filter(item -> !item.getKey().equals("page")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); return searchAggregationOption; } AggregationOptionToSearchAggregationOptionConverter(final String attributeCode,
                                                               final FilterAttributeMetadata filterAttributeMetadata,
                                                               final Map<String, String> filters); @Override SearchAggregationOption apply(final AggregationOption aggregationOption); }
AggregationOptionToSearchAggregationOptionConverter implements Function<AggregationOption, SearchAggregationOption> { @Override public SearchAggregationOption apply(final AggregationOption aggregationOption) { SearchAggregationOptionImpl searchAggregationOption = new SearchAggregationOptionImpl(); if (filterAttributeMetadata != null && FilterAttributeMetadataImpl.INPUT_TYPE_BOOLEAN.equals(filterAttributeMetadata .getAttributeInputType())) { searchAggregationOption.setDisplayLabel(("0".equalsIgnoreCase(aggregationOption.getLabel()) ? "No" : "Yes")); } else { searchAggregationOption.setDisplayLabel(aggregationOption.getLabel()); } searchAggregationOption.setCount(aggregationOption.getCount()); searchAggregationOption.setFilterValue(aggregationOption.getValue()); Map<String, String> newFilters = new HashMap<>(filters); newFilters.put(attributeCode, aggregationOption.getValue()); searchAggregationOption.setAddFilterMap(newFilters.entrySet().stream() .filter(item -> !item.getKey().equals("page")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); return searchAggregationOption; } AggregationOptionToSearchAggregationOptionConverter(final String attributeCode,
                                                               final FilterAttributeMetadata filterAttributeMetadata,
                                                               final Map<String, String> filters); @Override SearchAggregationOption apply(final AggregationOption aggregationOption);  }