Search in sources :

Example 1 with SelectedFacetValuesBuilder

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

the class UiSelectedFacets method toSelectedFacetValues.

/**
 * Convert this Ui Selected Facets to a SelectedFacetValues.
 * @return ListFilter for these Facets
 */
public SelectedFacetValues toSelectedFacetValues() {
    final SelectedFacetValuesBuilder selectedFacetValuesBuilder = SelectedFacetValues.empty();
    // facet selection list.
    for (final Map.Entry<String, String> entry : entrySet()) {
        final FacetDefinition facetDefinition = Home.getApp().getDefinitionSpace().resolve(entry.getKey(), FacetDefinition.class);
        if (facetDefinition.isRangeFacet()) {
            final String label = entry.getValue();
            for (final FacetValue facet : facetDefinition.getFacetRanges()) {
                if (facet.getLabel().getDisplay().equals(label)) {
                    selectedFacetValuesBuilder.add(facetDefinition, facet);
                    break;
                }
            }
        } else {
            final String term = entry.getValue();
            final MessageText label = MessageText.of(term);
            final String query = facetDefinition.getDtField().getName() + ":\"" + term + "\"";
            final FacetValue facetValue = new FacetValue(term, ListFilter.of(query), label);
            selectedFacetValuesBuilder.add(facetDefinition, facetValue);
        }
    }
    return selectedFacetValuesBuilder.build();
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) SelectedFacetValuesBuilder(io.vertigo.dynamo.collections.model.SelectedFacetValues.SelectedFacetValuesBuilder) MessageText(io.vertigo.core.locale.MessageText) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with SelectedFacetValuesBuilder

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

the class SelectedFacetValuesDeserializer method deserialize.

@Override
public SelectedFacetValues deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) {
    final SelectedFacetValuesBuilder selectedFacetValuesBuilder = SelectedFacetValues.empty();
    final JsonObject jsonObject = json.getAsJsonObject();
    for (final Entry<String, JsonElement> entry : jsonObject.entrySet()) {
        final FacetDefinition facetDefinition = Home.getApp().getDefinitionSpace().resolve(entry.getKey(), FacetDefinition.class);
        if (facetDefinition.isRangeFacet()) {
            appendRangeFacetValues(entry.getValue(), facetDefinition, selectedFacetValuesBuilder);
        } else {
            appendTermFacetValues(entry.getValue(), facetDefinition, selectedFacetValuesBuilder);
        }
    }
    return selectedFacetValuesBuilder.build();
}
Also used : SelectedFacetValuesBuilder(io.vertigo.dynamo.collections.model.SelectedFacetValues.SelectedFacetValuesBuilder) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition)

Aggregations

FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)2 SelectedFacetValuesBuilder (io.vertigo.dynamo.collections.model.SelectedFacetValues.SelectedFacetValuesBuilder)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 MessageText (io.vertigo.core.locale.MessageText)1 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1