Search in sources :

Example 1 with DataType

use of io.vertigo.dynamo.domain.metamodel.DataType in project vertigo by KleeGroup.

the class ESSearchRequestBuilder method rangeFacetToAggregationBuilder.

private static AggregationBuilder rangeFacetToAggregationBuilder(final FacetDefinition facetDefinition, final DtField dtField) {
    // facette par range
    final DataType dataType = dtField.getDomain().getDataType();
    if (dataType == DataType.Date) {
        return dateRangeFacetToAggregationBuilder(facetDefinition, dtField);
    } else if (dataType.isNumber()) {
        return numberRangeFacetToAggregationBuilder(facetDefinition, dtField);
    }
    final List<KeyedFilter> filters = new ArrayList<>();
    for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
        final String filterValue = facetRange.getListFilter().getFilterValue();
        Assertion.checkState(filterValue.contains(dtField.getName()), "RangeFilter query ({1}) should use defined fieldName {0}", dtField.getName(), filterValue);
        filters.add(new KeyedFilter(filterValue, QueryBuilders.queryStringQuery(filterValue)));
    }
    return AggregationBuilders.filters(facetDefinition.getName(), filters.toArray(new KeyedFilter[filters.size()]));
}
Also used : KeyedFilter(org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator.KeyedFilter) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) ArrayList(java.util.ArrayList) DataType(io.vertigo.dynamo.domain.metamodel.DataType)

Example 2 with DataType

use of io.vertigo.dynamo.domain.metamodel.DataType in project vertigo by KleeGroup.

the class AbstractSearchLoader method getLowestIdValue.

private P getLowestIdValue(final DtDefinition dtDefinition) {
    final DtField idField = dtDefinition.getIdField().get();
    final DataType idDataType = idField.getDomain().getDataType();
    P pkValue;
    switch(idDataType) {
        case Integer:
            pkValue = (P) Integer.valueOf(-1);
            break;
        case Long:
            pkValue = (P) Long.valueOf(-1);
            break;
        case String:
            pkValue = (P) "";
            break;
        case BigDecimal:
        case DataStream:
        case Boolean:
        case Double:
        case Date:
        default:
            throw new IllegalArgumentException("Type's PK " + idDataType.name() + " of " + dtDefinition.getClassSimpleName() + " is not supported, prefer int, long or String ID.");
    }
    return pkValue;
}
Also used : DataType(io.vertigo.dynamo.domain.metamodel.DataType) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 3 with DataType

use of io.vertigo.dynamo.domain.metamodel.DataType in project vertigo by KleeGroup.

the class ESSearchRequestBuilder method rangeFacetToAggregationBuilder.

private static AggregationBuilder<?> rangeFacetToAggregationBuilder(final FacetDefinition facetDefinition, final DtField dtField) {
    // facette par range
    final DataType dataType = dtField.getDomain().getDataType();
    if (dataType == DataType.Date) {
        return dateRangeFacetToAggregationBuilder(facetDefinition, dtField);
    } else if (dataType.isNumber()) {
        return numberRangeFacetToAggregationBuilder(facetDefinition, dtField);
    }
    final FiltersAggregationBuilder filters = AggregationBuilders.filters(facetDefinition.getName());
    for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
        final String filterValue = facetRange.getListFilter().getFilterValue();
        Assertion.checkState(filterValue.contains(dtField.getName()), "RangeFilter query ({1}) should use defined fieldName {0}", dtField.getName(), filterValue);
        filters.filter(filterValue, QueryBuilders.queryStringQuery(filterValue));
    }
    return filters;
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) FiltersAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder) DataType(io.vertigo.dynamo.domain.metamodel.DataType)

Example 4 with DataType

use of io.vertigo.dynamo.domain.metamodel.DataType in project vertigo by KleeGroup.

the class DomainDynamicRegistry method createDomain.

private static Domain createDomain(final DefinitionSpace definitionSpace, final DslDefinition xdomain) {
    final String domainName = xdomain.getName();
    final List<String> constraintNames = xdomain.getDefinitionLinkNames("constraint");
    final String type = xdomain.getDefinitionLinkName("dataType");
    final Boolean multiple = (Boolean) xdomain.getPropertyValue(KspProperty.MULTIPLE);
    final Properties properties = extractProperties(xdomain);
    final DomainBuilder domainBuilder;
    if ("DtObject".equals(type)) {
        domainBuilder = Domain.builder(domainName, properties.getValue(DtProperty.TYPE), false);
    } else if ("DtList".equals(type)) {
        domainBuilder = Domain.builder(domainName, properties.getValue(DtProperty.TYPE), true);
    } else {
        final DataType dataType = DataType.valueOf(type);
        domainBuilder = Domain.builder(domainName, dataType, multiple == null ? false : multiple);
        // only primitive can have a formatter
        final boolean hasFormatter = !xdomain.getDefinitionLinkNames("formatter").isEmpty();
        if (hasFormatter) {
            final String formatterName = xdomain.getDefinitionLinkName("formatter");
            final FormatterDefinition formatterDefinition = definitionSpace.resolve(formatterName, FormatterDefinition.class);
            // ---
            domainBuilder.withFormatter(formatterDefinition);
        }
    }
    return domainBuilder.withConstraints(createConstraints(definitionSpace, constraintNames)).withProperties(properties).build();
}
Also used : DomainBuilder(io.vertigo.dynamo.domain.metamodel.DomainBuilder) DataType(io.vertigo.dynamo.domain.metamodel.DataType) Properties(io.vertigo.dynamo.domain.metamodel.Properties) FormatterDefinition(io.vertigo.dynamo.domain.metamodel.FormatterDefinition)

Example 5 with DataType

use of io.vertigo.dynamo.domain.metamodel.DataType in project vertigo by KleeGroup.

the class DtListPatternFilterUtil method createDtListFilterForPattern.

static <D extends DtObject> Predicate<D> createDtListFilterForPattern(final FilterPattern filterPattern, final String[] parsedFilter, final DtDefinition dtDefinition) {
    Assertion.checkNotNull(filterPattern);
    Assertion.checkNotNull(parsedFilter);
    Assertion.checkNotNull(dtDefinition);
    // -----
    // Si on trouve un pattern, on passe sur du code spécifique
    // attention parsedFilter[0] = filtre entier
    final String fieldName = parsedFilter[1];
    final DtField dtField = dtDefinition.getField(fieldName);
    final DataType dataType = dtField.getDomain().getDataType();
    switch(filterPattern) {
        case Range:
            return createDtListRangeFilter(parsedFilter, fieldName, dataType);
        case Term:
            return createDtListTermFilter(parsedFilter, fieldName, dataType);
        default:
            throw new VSystemException("La chaine de filtrage: {0} , ne respecte pas la syntaxe {1}.", parsedFilter[0], filterPattern.getPattern().pattern());
    }
}
Also used : DataType(io.vertigo.dynamo.domain.metamodel.DataType) VSystemException(io.vertigo.lang.VSystemException) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Aggregations

DataType (io.vertigo.dynamo.domain.metamodel.DataType)5 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)2 DtField (io.vertigo.dynamo.domain.metamodel.DtField)2 DomainBuilder (io.vertigo.dynamo.domain.metamodel.DomainBuilder)1 FormatterDefinition (io.vertigo.dynamo.domain.metamodel.FormatterDefinition)1 Properties (io.vertigo.dynamo.domain.metamodel.Properties)1 VSystemException (io.vertigo.lang.VSystemException)1 ArrayList (java.util.ArrayList)1 FiltersAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder)1 KeyedFilter (org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator.KeyedFilter)1