use of org.springframework.data.elasticsearch.core.convert.DateRangePropertyValueConverter in project spring-data-elasticsearch by spring-projects.
the class SimpleElasticsearchPersistentProperty method initPropertyValueConverter.
/**
* Initializes the property converter for this {@link PersistentProperty}, if any.
*/
private void initPropertyValueConverter() {
initPropertyValueConverterFromAnnotation();
if (hasPropertyValueConverter()) {
return;
}
Class<?> actualType = getActualTypeOrNull();
if (actualType == null) {
return;
}
Field field = findAnnotation(Field.class);
if (field == null) {
return;
}
switch(field.type()) {
case Date:
case Date_Nanos:
{
List<ElasticsearchDateConverter> dateConverters = getDateConverters(field, actualType);
if (dateConverters.isEmpty()) {
LOGGER.warn(String.format("No date formatters configured for property '%s'.", getName()));
return;
}
if (TemporalAccessor.class.isAssignableFrom(actualType)) {
propertyValueConverter = new TemporalPropertyValueConverter(this, dateConverters);
} else if (Date.class.isAssignableFrom(actualType)) {
propertyValueConverter = new DatePropertyValueConverter(this, dateConverters);
} else {
LOGGER.warn(String.format("Unsupported type '%s' for date property '%s'.", actualType, getName()));
}
break;
}
case Date_Range:
{
if (!Range.class.isAssignableFrom(actualType)) {
return;
}
List<ElasticsearchDateConverter> dateConverters = getDateConverters(field, actualType);
if (dateConverters.isEmpty()) {
LOGGER.warn(String.format("No date formatters configured for property '%s'.", getName()));
return;
}
Class<?> genericType = getTypeInformation().getTypeArguments().get(0).getType();
if (TemporalAccessor.class.isAssignableFrom(genericType)) {
propertyValueConverter = new TemporalRangePropertyValueConverter(this, dateConverters);
} else if (Date.class.isAssignableFrom(genericType)) {
propertyValueConverter = new DateRangePropertyValueConverter(this, dateConverters);
} else {
LOGGER.warn(String.format("Unsupported generic type '{%s' for date range property '%s'.", genericType, getName()));
}
break;
}
case Integer_Range:
case Float_Range:
case Long_Range:
case Double_Range:
{
if (!Range.class.isAssignableFrom(actualType)) {
return;
}
Class<?> genericType = getTypeInformation().getTypeArguments().get(0).getType();
if ((field.type() == FieldType.Integer_Range && !Integer.class.isAssignableFrom(genericType)) || (field.type() == FieldType.Float_Range && !Float.class.isAssignableFrom(genericType)) || (field.type() == FieldType.Long_Range && !Long.class.isAssignableFrom(genericType)) || (field.type() == FieldType.Double_Range && !Double.class.isAssignableFrom(genericType))) {
LOGGER.warn(String.format("Unsupported generic type '%s' for range field type '%s' of property '%s'.", genericType, field.type(), getName()));
return;
}
propertyValueConverter = new NumberRangePropertyValueConverter(this);
break;
}
case Ip_Range:
{
// TODO currently unsupported, needs a library like https://seancfoley.github.io/IPAddress/
}
default:
break;
}
}
Aggregations