Example usage for org.springframework.data.elasticsearch.annotations FieldType toString

List of usage examples for org.springframework.data.elasticsearch.annotations FieldType toString

Introduction

In this page you can find the example usage for org.springframework.data.elasticsearch.annotations FieldType toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.github.vanroy.springdata.jest.MappingBuilder.java

private static void mapEntity(XContentBuilder xContentBuilder, Class clazz, boolean isRootObject,
        String idFieldName, String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType,
        Field fieldAnnotation) throws IOException {

    java.lang.reflect.Field[] fields = retrieveFields(clazz);

    if (!isRootObject && (isAnyPropertyAnnotatedAsField(fields) || nestedOrObjectField)) {
        String type = FieldType.Object.toString().toLowerCase();
        if (nestedOrObjectField) {
            type = fieldType.toString().toLowerCase();
        }/*  www . j a  va2s .  c  om*/
        XContentBuilder t = xContentBuilder.startObject(nestedObjectFieldName).field(FIELD_TYPE, type);

        if (nestedOrObjectField && FieldType.Nested == fieldType && fieldAnnotation.includeInParent()) {
            t.field("include_in_parent", fieldAnnotation.includeInParent());
        }
        t.startObject(FIELD_PROPERTIES);
    }

    for (java.lang.reflect.Field field : fields) {

        if (field.isAnnotationPresent(Transient.class) || isInIgnoreFields(field)) {
            continue;
        }

        if (field.isAnnotationPresent(Mapping.class)) {
            String mappingPath = field.getAnnotation(Mapping.class).mappingPath();
            if (isNotBlank(mappingPath)) {
                ClassPathResource mappings = new ClassPathResource(mappingPath);
                if (mappings.exists()) {
                    xContentBuilder.rawField(field.getName(), mappings.getInputStream());
                    continue;
                }
            }
        }

        boolean isGeoPointField = isGeoPointField(field);
        boolean isCompletionField = isCompletionField(field);

        Field singleField = field.getAnnotation(Field.class);
        if (!isGeoPointField && !isCompletionField && isEntity(field) && isAnnotated(field)) {
            if (singleField == null) {
                continue;
            }
            boolean nestedOrObject = isNestedOrObjectField(field);
            mapEntity(xContentBuilder, getFieldType(field), false, EMPTY, field.getName(), nestedOrObject,
                    singleField.type(), field.getAnnotation(Field.class));
            if (nestedOrObject) {
                continue;
            }
        }

        MultiField multiField = field.getAnnotation(MultiField.class);

        if (isGeoPointField) {
            applyGeoPointFieldMapping(xContentBuilder, field);
        }

        if (isCompletionField) {
            CompletionField completionField = field.getAnnotation(CompletionField.class);
            applyCompletionFieldMapping(xContentBuilder, field, completionField);
        }

        if (isRootObject && singleField != null && isIdField(field, idFieldName)) {
            applyDefaultIdFieldMapping(xContentBuilder, field);
        } else if (multiField != null) {
            addMultiFieldMapping(xContentBuilder, field, multiField, isNestedOrObjectField(field));
        } else if (singleField != null) {
            addSingleFieldMapping(xContentBuilder, field, singleField, isNestedOrObjectField(field));
        }
    }

    if (!isRootObject && isAnyPropertyAnnotatedAsField(fields) || nestedOrObjectField) {
        xContentBuilder.endObject().endObject();
    }
}