Search in sources :

Example 1 with FacetedQuery

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

the class FacetManagerTest method testFacetListByTerm.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testFacetListByTerm() {
    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);
    testFacetResultByTerm(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 2 with FacetedQuery

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

the class FacetManagerTest method testFilterFacetListByRange.

/**
 * Test le facettage par range d'une liste.
 * Et le filtrage par une facette.
 */
@Test
public void testFilterFacetListByRange() {
    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);
    // on applique une facette
    final FacetedQuery query = addFacetQuery("FCT_YEAR_CAR", "avant", result);
    final FacetedQueryResult<SmartCar, DtList<SmartCar>> resultFiltered = collectionsManager.facetList(result.getSource(), query);
    Assert.assertEquals(smartCarDataBase.getCarsBefore(2000), resultFiltered.getCount());
}
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 3 with FacetedQuery

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

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

the class FacetManagerTest method testFilterFacetListByTerm.

/**
 * Test le facettage par term d'une liste.
 * Et le filtrage par une facette.
 */
@Test
public void testFilterFacetListByTerm() {
    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);
    // on applique une facette
    final FacetedQuery query = addFacetQuery("FCT_MANUFACTURER_CAR", "peugeot", result);
    final FacetedQueryResult<SmartCar, DtList<SmartCar>> resultFiltered = collectionsManager.facetList(result.getSource(), query);
    Assert.assertEquals(smartCarDataBase.getCarsByManufacturer("peugeot").size(), (int) resultFiltered.getCount());
}
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 5 with FacetedQuery

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

the class SearchTestWebServices method testFacetedQueryResult.

@POST("/facetedResult")
public FacetedQueryResult<Contact, DtList<Contact>> testFacetedQueryResult(final SelectedFacetValues selectedFacetValues) {
    final DtList<Contact> allContacts = asDtList(contactDao.getList(), Contact.class);
    final FacetedQueryDefinition facetedQueryDefinition = Home.getApp().getDefinitionSpace().resolve("QRY_CONTACT_FACET", FacetedQueryDefinition.class);
    final FacetedQuery facetedQuery = new FacetedQuery(facetedQueryDefinition, selectedFacetValues);
    return collectionsManager.facetList(allContacts, facetedQuery);
}
Also used : FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) Contact(io.vertigo.vega.webservice.data.domain.Contact) POST(io.vertigo.vega.webservice.stereotype.POST)

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