Search in sources :

Example 1 with SelectedFacetValues

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

the class FacetManagerTest method addFacetQuery.

private static FacetedQuery addFacetQuery(final String facetName, final String facetValueLabel, final FacetedQueryResult<SmartCar, ?> result) {
    // pb d'initialisation, et assert.notNull ne suffit pas
    FacetValue facetFilter = null;
    final Facet yearFacet = getFacetByName(result, facetName);
    for (final Entry<FacetValue, Long> entry : yearFacet.getFacetValues().entrySet()) {
        if (entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH).contains(facetValueLabel)) {
            facetFilter = entry.getKey();
            break;
        }
    }
    if (facetFilter == 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(yearFacet.getDefinition(), facetFilter).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 2 with SelectedFacetValues

use of io.vertigo.dynamo.collections.model.SelectedFacetValues 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 3 with SelectedFacetValues

use of io.vertigo.dynamo.collections.model.SelectedFacetValues 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 4 with SelectedFacetValues

use of io.vertigo.dynamo.collections.model.SelectedFacetValues 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

Facet (io.vertigo.dynamo.collections.model.Facet)4 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)4 FacetedQuery (io.vertigo.dynamo.collections.model.FacetedQuery)4 SelectedFacetValues (io.vertigo.dynamo.collections.model.SelectedFacetValues)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 FacetedQueryResult (io.vertigo.dynamo.collections.model.FacetedQueryResult)1 DtField (io.vertigo.dynamo.domain.metamodel.DtField)1 DtList (io.vertigo.dynamo.domain.model.DtList)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 Assertion (io.vertigo.lang.Assertion)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1