Search in sources :

Example 6 with FacetedQuery

use of io.vertigo.dynamo.collections.model.FacetedQuery in project vertigo by KleeGroup.

the class FacetManagerTest method testFacetListByRange.

/**
 * Test le facettage par range d'une liste.
 */
@Test
public void testFacetListByRange() {
    final DtList<SmartCar> cars = smartCarDataBase.getAllCars();
    final FacetedQuery facetedQuery = new FacetedQuery(carFacetQueryDefinition, SelectedFacetValues.empty().build());
    final FacetedQueryResult<SmartCar, DtList<SmartCar>> result = collectionsManager.facetList(cars, facetedQuery);
    testFacetResultByRange(result);
}
Also used : SmartCar(io.vertigo.dynamo.collections.data.domain.SmartCar) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 7 with FacetedQuery

use of io.vertigo.dynamo.collections.model.FacetedQuery in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method createFacetQuery.

private static FacetedQuery createFacetQuery(final String facetName, final String facetValueLabel, final FacetedQueryResult<Car, ?> result) {
    // pb d'initialisation, et assert.notNull ne suffit pas
    FacetValue facetValue = null;
    final Facet facet = getFacetByName(result, facetName);
    for (final Entry<FacetValue, Long> entry : facet.getFacetValues().entrySet()) {
        if (entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH).contains(facetValueLabel)) {
            facetValue = entry.getKey();
            break;
        }
    }
    if (facetValue == null) {
        throw new IllegalArgumentException("Pas de FacetValue contenant " + facetValueLabel + " dans la facette " + facetName);
    }
    final FacetedQuery previousQuery = result.getFacetedQuery().get();
    final SelectedFacetValues queryFilters = SelectedFacetValues.of(previousQuery.getSelectedFacetValues()).add(facet.getDefinition(), facetValue).build();
    return new FacetedQuery(previousQuery.getDefinition(), queryFilters);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 8 with FacetedQuery

use of io.vertigo.dynamo.collections.model.FacetedQuery in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method createFacetQuery.

private static FacetedQuery createFacetQuery(final String facetName, final String facetValueLabel, final FacetedQueryResult<Item, ?> result) {
    // pb d'initialisation, et assert.notNull ne suffit pas
    FacetValue facetValue = null;
    final Facet facet = getFacetByName(result, facetName);
    for (final Entry<FacetValue, Long> entry : facet.getFacetValues().entrySet()) {
        if (entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH).contains(facetValueLabel)) {
            facetValue = entry.getKey();
            break;
        }
    }
    if (facetValue == null) {
        throw new IllegalArgumentException("Pas de FacetValue contenant " + facetValueLabel + " dans la facette " + facetName);
    }
    final FacetedQuery previousQuery = result.getFacetedQuery().get();
    final SelectedFacetValues queryFilters = SelectedFacetValues.of(previousQuery.getSelectedFacetValues()).add(facet.getDefinition(), facetValue).build();
    return new FacetedQuery(previousQuery.getDefinition(), queryFilters);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 9 with FacetedQuery

use of io.vertigo.dynamo.collections.model.FacetedQuery in project vertigo by KleeGroup.

the class CollectionsManagerImpl method filter.

// =========================================================================
// =======================Filtrage==========================================
// =========================================================================
private <D extends DtObject> Predicate<D> filter(final FacetedQuery facetedQuery) {
    final SelectedFacetValues selectedFacetValues = facetedQuery.getSelectedFacetValues();
    Predicate<D> predicate = list -> true;
    for (final FacetDefinition facetDefinition : facetedQuery.getDefinition().getFacetDefinitions()) {
        if (!selectedFacetValues.getFacetValues(facetDefinition).isEmpty()) {
            Predicate<D> predicateValue = list -> false;
            for (final FacetValue facetValue : selectedFacetValues.getFacetValues(facetDefinition)) {
                predicateValue = predicateValue.or(this.filter(facetValue.getListFilter()));
            }
            predicate = predicate.and(predicateValue);
        }
    }
    return predicate;
}
Also used : ListFilter(io.vertigo.dynamo.collections.ListFilter) DtField(io.vertigo.dynamo.domain.metamodel.DtField) Facet(io.vertigo.dynamo.collections.model.Facet) Inject(javax.inject.Inject) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Home(io.vertigo.app.Home) StoreManager(io.vertigo.dynamo.store.StoreManager) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) DtListPatternFilter(io.vertigo.dynamo.impl.collections.functions.filter.DtListPatternFilter) Predicate(java.util.function.Predicate) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) FacetFactory(io.vertigo.dynamo.impl.collections.facet.model.FacetFactory) DtList(io.vertigo.dynamo.domain.model.DtList) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) List(java.util.List) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) DtObject(io.vertigo.dynamo.domain.model.DtObject) Optional(java.util.Optional) IndexDtListFunctionBuilder(io.vertigo.dynamo.collections.IndexDtListFunctionBuilder) VCollectors(io.vertigo.dynamo.domain.util.VCollectors) Comparator(java.util.Comparator) Collections(java.util.Collections) CollectionsManager(io.vertigo.dynamo.collections.CollectionsManager) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition)

Aggregations

FacetedQuery (io.vertigo.dynamo.collections.model.FacetedQuery)9 DtList (io.vertigo.dynamo.domain.model.DtList)5 SmartCar (io.vertigo.dynamo.collections.data.domain.SmartCar)4 Facet (io.vertigo.dynamo.collections.model.Facet)4 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)4 SelectedFacetValues (io.vertigo.dynamo.collections.model.SelectedFacetValues)4 Test (org.junit.Test)4 Home (io.vertigo.app.Home)1 CollectionsManager (io.vertigo.dynamo.collections.CollectionsManager)1 IndexDtListFunctionBuilder (io.vertigo.dynamo.collections.IndexDtListFunctionBuilder)1 ListFilter (io.vertigo.dynamo.collections.ListFilter)1 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)1 FacetedQueryDefinition (io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)1 FacetedQueryResult (io.vertigo.dynamo.collections.model.FacetedQueryResult)1 DtField (io.vertigo.dynamo.domain.metamodel.DtField)1 DtObject (io.vertigo.dynamo.domain.model.DtObject)1 VCollectors (io.vertigo.dynamo.domain.util.VCollectors)1 FacetFactory (io.vertigo.dynamo.impl.collections.facet.model.FacetFactory)1 DtListPatternFilter (io.vertigo.dynamo.impl.collections.functions.filter.DtListPatternFilter)1 StoreManager (io.vertigo.dynamo.store.StoreManager)1