Search in sources :

Example 1 with Field

use of org.motechproject.mds.annotations.Field in project motech by motech.

the class RestIgnoreProcessor method process.

@Override
protected void process(AnnotatedElement element) {
    Field fieldAnnotation = ReflectionsUtil.getAnnotationClassLoaderSafe(element, clazz, Field.class);
    String fieldName = MemberUtil.getFieldName(element);
    String field = ReflectionsUtil.getAnnotationValue(fieldAnnotation, NAME, fieldName);
    add(field);
}
Also used : Field(org.motechproject.mds.annotations.Field)

Example 2 with Field

use of org.motechproject.mds.annotations.Field in project motech by motech.

the class UIFilterableProcessor method process.

@Override
protected void process(AnnotatedElement element) {
    Class<?> classType = MemberUtil.getCorrectType(element);
    if (null != classType) {
        UIFilterable annotation = ReflectionsUtil.getAnnotationSelfOrAccessor(element, UIFilterable.class);
        if (null != annotation) {
            if (isCorrectType(classType)) {
                Field fieldAnnotation = ReflectionsUtil.getAnnotationClassLoaderSafe(element, classType, Field.class);
                String fieldName = MemberUtil.getFieldName(element);
                String field = ReflectionsUtil.getAnnotationValue(fieldAnnotation, NAME, fieldName);
                add(field);
            } else {
                LOGGER.warn("@UIFilterable found on field of type {}, filters on this type are not supported", classType.getName());
            }
        }
    } else {
        LOGGER.warn("Field type is unknown in: {}", element);
    }
}
Also used : Field(org.motechproject.mds.annotations.Field) UIFilterable(org.motechproject.mds.annotations.UIFilterable)

Example 3 with Field

use of org.motechproject.mds.annotations.Field in project motech by motech.

the class FieldProcessor method process.

@Override
protected void process(AnnotatedElement element) {
    AccessibleObject ac = (AccessibleObject) element;
    Class<?> classType = MemberUtil.getCorrectType(ac);
    Class<?> genericType = MemberUtil.getGenericType(element);
    Class<?> declaringClass = MemberUtil.getDeclaringClass(ac);
    Class<?> valueType = null;
    if (null != classType) {
        if (Map.class.isAssignableFrom(classType)) {
            valueType = MemberUtil.getGenericType(element, 1);
        }
        String fieldName = MemberUtil.getFieldName(ac);
        FieldDto currentField = getFieldByName(declaringClass.getName(), fieldName);
        boolean isRelationship = ReflectionsUtil.hasAnnotationClassLoaderSafe(genericType, genericType, Entity.class);
        boolean isOwningSide = isRelationship && getMappedBy(ac) == null;
        boolean isCollection = Collection.class.isAssignableFrom(classType);
        Field annotation = getAnnotationClassLoaderSafe(ac, classType, Field.class);
        String relatedFieldName = getRelatedFieldName(ac, classType, genericType, declaringClass, isRelationship);
        java.lang.reflect.Field relatedField = (relatedFieldName != null) ? ReflectionUtils.findField(genericType, relatedFieldName) : null;
        boolean relatedFieldIsCollection = isRelatedFieldCollection(relatedField);
        boolean isTextArea = getAnnotationValue(annotation, TYPE, EMPTY).equalsIgnoreCase("text");
        TypeDto type = getCorrectType(classType, isCollection, isRelationship, relatedFieldIsCollection);
        FieldBasicDto basic = new FieldBasicDto();
        basic.setDisplayName(isUiChanged(currentField) ? currentField.getBasic().getDisplayName() : getAnnotationValue(annotation, DISPLAY_NAME, convertFromCamelCase(fieldName)));
        basic.setName(fieldName);
        basic.setDefaultValue(getDefaultValueForField(annotation, classType));
        basic.setRequired(isFieldRequired(annotation, classType));
        basic.setUnique(isFieldUnique(ac));
        FieldDto field = new FieldDto();
        if (null != annotation) {
            basic.setTooltip(isUiChanged(currentField) ? currentField.getBasic().getTooltip() : annotation.tooltip());
            basic.setPlaceholder(annotation.placeholder());
            String fn = getAnnotationValue(annotation, NAME, EMPTY);
            if (!fn.equals(EMPTY)) {
                field.addMetadata(new MetadataDto(DATABASE_COLUMN_NAME, fn));
            }
        }
        field.setEntityId(entity.getId());
        field.setType(type);
        field.setBasic(basic);
        field.setValidation(createValidation(ac, type));
        field.setReadOnly(true);
        field.setNonEditable(false);
        field.setNonDisplayable(false);
        field.setUiChanged(isUiChanged(currentField));
        field.setUiFilterable(isUiFilterable(currentField));
        setFieldSettings(ac, classType, isRelationship, isTextArea, field);
        setFieldMetadata(classType, genericType, valueType, isCollection, isRelationship, relatedFieldIsCollection, isOwningSide, field, relatedFieldName);
        add(field);
    } else {
        LOGGER.warn("Field type is unknown in: {}", ac);
    }
}
Also used : PredicateUtil.entityField(org.motechproject.mds.annotations.internal.PredicateUtil.entityField) Field(org.motechproject.mds.annotations.Field) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) AccessibleObject(java.lang.reflect.AccessibleObject) TypeDto(org.motechproject.mds.dto.TypeDto) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

Field (org.motechproject.mds.annotations.Field)3 AccessibleObject (java.lang.reflect.AccessibleObject)1 UIFilterable (org.motechproject.mds.annotations.UIFilterable)1 PredicateUtil.entityField (org.motechproject.mds.annotations.internal.PredicateUtil.entityField)1 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)1 FieldDto (org.motechproject.mds.dto.FieldDto)1 MetadataDto (org.motechproject.mds.dto.MetadataDto)1 TypeDto (org.motechproject.mds.dto.TypeDto)1