Search in sources :

Example 1 with SupportedFieldType

use of org.broadleafcommerce.common.presentation.client.SupportedFieldType in project BroadleafCommerce by BroadleafCommerce.

the class DynamicEntityDaoImpl method buildBasicProperty.

protected void buildBasicProperty(Field field, Class<?> targetClass, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> presentationAttributes, List<Property> componentProperties, Map<String, FieldMetadata> fields, String idProperty, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String propertyName, Type type, boolean propertyForeignKey, int additionalForeignKeyIndexPosition, Boolean isComponentPrefix, String parentPrefix) {
    FieldMetadata presentationAttribute = presentationAttributes.get(propertyName);
    Boolean amIExcluded = isParentExcluded || !testPropertyInclusion(presentationAttribute);
    Boolean includeField = !testPropertyRecursion(prefix, parentClasses, propertyName, targetClass, ceilingEntityFullyQualifiedClassname, isComponentPrefix, parentPrefix);
    SupportedFieldType explicitType = null;
    if (presentationAttribute != null && presentationAttribute instanceof BasicFieldMetadata) {
        explicitType = ((BasicFieldMetadata) presentationAttribute).getExplicitFieldType();
    }
    Class<?> returnedClass = type.getReturnedClass();
    checkProp: {
        if (type.isComponentType() && includeField) {
            buildComponentProperties(targetClass, foreignField, additionalForeignFields, additionalNonPersistentProperties, mergedPropertyType, fields, idProperty, populateManyToOneFields, includeFields, excludeFields, configurationKey, ceilingEntityFullyQualifiedClassname, propertyName, type, returnedClass, parentClasses, amIExcluded, prefix, parentPrefix);
            break checkProp;
        }
        /*
             * Currently we do not support ManyToOne fields whose class type is the same
             * as the target type, since this forms an infinite loop and will cause a stack overflow.
             */
        if (type.isEntityType() && !returnedClass.isAssignableFrom(targetClass) && populateManyToOneFields && includeField) {
            buildEntityProperties(fields, foreignField, additionalForeignFields, additionalNonPersistentProperties, populateManyToOneFields, includeFields, excludeFields, configurationKey, ceilingEntityFullyQualifiedClassname, propertyName, returnedClass, targetClass, parentClasses, prefix, amIExcluded, parentPrefix);
            break checkProp;
        }
    }
    // Don't include this property if it failed manyToOne inclusion and is not a specified foreign key
    if (includeField || propertyForeignKey || additionalForeignKeyIndexPosition >= 0) {
        defaultFieldMetadataProvider.addMetadataFromFieldType(new AddMetadataFromFieldTypeRequest(field, targetClass, foreignField, additionalForeignFields, mergedPropertyType, componentProperties, idProperty, prefix, propertyName, type, propertyForeignKey, additionalForeignKeyIndexPosition, presentationAttributes, presentationAttribute, explicitType, returnedClass, this), fields);
    }
}
Also used : SupportedFieldType(org.broadleafcommerce.common.presentation.client.SupportedFieldType) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) AddMetadataFromFieldTypeRequest(org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.AddMetadataFromFieldTypeRequest)

Example 2 with SupportedFieldType

use of org.broadleafcommerce.common.presentation.client.SupportedFieldType in project BroadleafCommerce by BroadleafCommerce.

the class MapFieldsFieldMetadataProvider method addMetadataFromFieldType.

@Override
public MetadataProviderResponse addMetadataFromFieldType(AddMetadataFromFieldTypeRequest addMetadataFromFieldTypeRequest, Map<String, FieldMetadata> metadata) {
    if (!canHandleFieldForTypeMetadata(addMetadataFromFieldTypeRequest, metadata)) {
        return MetadataProviderResponse.NOT_HANDLED;
    }
    // look for any map field metadata that was previously added for the requested field
    for (Map.Entry<String, FieldMetadata> entry : addMetadataFromFieldTypeRequest.getPresentationAttributes().entrySet()) {
        if (entry.getKey().startsWith(addMetadataFromFieldTypeRequest.getRequestedPropertyName() + FieldManager.MAPFIELDSEPARATOR)) {
            TypeLocatorImpl typeLocator = new TypeLocatorImpl(new TypeResolver());
            Type myType = null;
            // first, check if an explicit type was declared
            String valueClass = ((BasicFieldMetadata) entry.getValue()).getMapFieldValueClass();
            if (valueClass != null) {
                myType = typeLocator.entity(valueClass);
            }
            if (myType == null) {
                SupportedFieldType fieldType = ((BasicFieldMetadata) entry.getValue()).getExplicitFieldType();
                Class<?> basicJavaType = getBasicJavaType(fieldType);
                if (basicJavaType != null) {
                    myType = typeLocator.basic(basicJavaType);
                }
            }
            if (myType == null) {
                java.lang.reflect.Type genericType = addMetadataFromFieldTypeRequest.getRequestedField().getGenericType();
                if (genericType instanceof ParameterizedType) {
                    ParameterizedType pType = (ParameterizedType) genericType;
                    Class<?> clazz = (Class<?>) pType.getActualTypeArguments()[1];
                    Class<?>[] entities = addMetadataFromFieldTypeRequest.getDynamicEntityDao().getAllPolymorphicEntitiesFromCeiling(clazz);
                    if (!ArrayUtils.isEmpty(entities)) {
                        myType = typeLocator.entity(entities[entities.length - 1]);
                    }
                }
            }
            if (myType == null) {
                throw new IllegalArgumentException("Unable to establish the type for the property (" + entry.getKey() + ")");
            }
            // add property for this map field as if it was a normal field
            super.addMetadataFromFieldType(new AddMetadataFromFieldTypeRequest(addMetadataFromFieldTypeRequest.getRequestedField(), addMetadataFromFieldTypeRequest.getTargetClass(), addMetadataFromFieldTypeRequest.getForeignField(), addMetadataFromFieldTypeRequest.getAdditionalForeignFields(), addMetadataFromFieldTypeRequest.getMergedPropertyType(), addMetadataFromFieldTypeRequest.getComponentProperties(), addMetadataFromFieldTypeRequest.getIdProperty(), addMetadataFromFieldTypeRequest.getPrefix(), entry.getKey(), myType, addMetadataFromFieldTypeRequest.isPropertyForeignKey(), addMetadataFromFieldTypeRequest.getAdditionalForeignKeyIndexPosition(), addMetadataFromFieldTypeRequest.getPresentationAttributes(), entry.getValue(), ((BasicFieldMetadata) entry.getValue()).getExplicitFieldType(), myType.getReturnedClass(), addMetadataFromFieldTypeRequest.getDynamicEntityDao()), metadata);
        }
    }
    return MetadataProviderResponse.HANDLED;
}
Also used : SupportedFieldType(org.broadleafcommerce.common.presentation.client.SupportedFieldType) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) TypeResolver(org.hibernate.type.TypeResolver) ParameterizedType(java.lang.reflect.ParameterizedType) SupportedFieldType(org.broadleafcommerce.common.presentation.client.SupportedFieldType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(org.hibernate.type.Type) TypeLocatorImpl(org.hibernate.internal.TypeLocatorImpl) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) Map(java.util.Map) AdminPresentationMap(org.broadleafcommerce.common.presentation.AdminPresentationMap) AddMetadataFromFieldTypeRequest(org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.AddMetadataFromFieldTypeRequest) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)

Example 3 with SupportedFieldType

use of org.broadleafcommerce.common.presentation.client.SupportedFieldType in project BroadleafCommerce by BroadleafCommerce.

the class DataDTOToMVELTranslator method buildExpression.

protected void buildExpression(ExpressionDTO expressionDTO, StringBuffer sb, String entityKey, BLCOperator operator, RuleBuilderFieldService fieldService) throws MVELTranslationException {
    String field = expressionDTO.getId();
    String overrideEntityKey = fieldService.getOverrideFieldEntityKey(field);
    if (overrideEntityKey != null) {
        entityKey = overrideEntityKey;
    }
    SupportedFieldType type = fieldService.getSupportedFieldType(field);
    SupportedFieldType secondaryType = fieldService.getSecondaryFieldType(field);
    Object[] value;
    if (type == null) {
        throw new MVELTranslationException(MVELTranslationException.SPECIFIED_FIELD_NOT_FOUND, "The DataDTO is not compatible with the RuleBuilderFieldService " + "associated with the current rules builder. Unable to find the field " + "specified: (" + field + ")");
    }
    value = extractBasicValues(expressionDTO.getValue());
    switch(operator) {
        case CONTAINS:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, CONTAINS_OPERATOR, true, false, false, false, false);
                break;
            }
        case CONTAINS_FIELD:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, CONTAINS_OPERATOR, true, true, false, false, false);
                break;
            }
        case ENDS_WITH:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, ENDS_WITH_OPERATOR, true, false, false, false, false);
                break;
            }
        case ENDS_WITH_FIELD:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, ENDS_WITH_OPERATOR, true, true, false, false, false);
                break;
            }
        case EQUALS:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, EQUALS_OPERATOR, false, false, false, false, false);
                break;
            }
        case EQUALS_FIELD:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, EQUALS_OPERATOR, false, true, false, false, false);
                break;
            }
        case GREATER_OR_EQUAL:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, GREATER_THAN_EQUALS_OPERATOR, false, false, false, false, false);
                break;
            }
        case GREATER_OR_EQUAL_FIELD:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, GREATER_THAN_EQUALS_OPERATOR, false, true, false, false, false);
                break;
            }
        case GREATER_THAN:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, GREATER_THAN_OPERATOR, false, false, false, false, false);
                break;
            }
        case GREATER_THAN_FIELD:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, GREATER_THAN_OPERATOR, false, true, false, false, false);
                break;
            }
        case ICONTAINS:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, CONTAINS_OPERATOR, true, false, true, false, false);
                break;
            }
        case IENDS_WITH:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, ENDS_WITH_OPERATOR, true, false, true, false, false);
                break;
            }
        case IEQUALS:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, EQUALS_OPERATOR, false, false, true, false, false);
                break;
            }
        case INOT_CONTAINS:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, CONTAINS_OPERATOR, true, false, true, true, false);
                break;
            }
        case INOT_ENDS_WITH:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, ENDS_WITH_OPERATOR, true, false, true, true, false);
                break;
            }
        case INOT_EQUAL:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, NOT_EQUALS_OPERATOR, false, false, true, false, false);
                break;
            }
        case INOT_STARTS_WITH:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, STARTS_WITH_OPERATOR, true, false, true, true, false);
                break;
            }
        case IS_NULL:
            {
                buildExpression(sb, entityKey, field, new Object[] { "null" }, type, secondaryType, EQUALS_OPERATOR, false, false, false, false, true);
                break;
            }
        case ISTARTS_WITH:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, STARTS_WITH_OPERATOR, true, false, true, false, false);
                break;
            }
        case LESS_OR_EQUAL:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, LESS_THAN_EQUALS_OPERATOR, false, false, false, false, false);
                break;
            }
        case LESS_OR_EQUAL_FIELD:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, LESS_THAN_EQUALS_OPERATOR, false, true, false, false, false);
                break;
            }
        case LESS_THAN:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, LESS_THAN_OPERATOR, false, false, false, false, false);
                break;
            }
        case LESS_THAN_FIELD:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, LESS_THAN_OPERATOR, false, true, false, false, false);
                break;
            }
        case NOT_CONTAINS:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, CONTAINS_OPERATOR, true, false, false, true, false);
                break;
            }
        case NOT_ENDS_WITH:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, ENDS_WITH_OPERATOR, true, false, false, true, false);
                break;
            }
        case NOT_EQUAL:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, NOT_EQUALS_OPERATOR, false, false, false, false, false);
                break;
            }
        case NOT_EQUAL_FIELD:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, NOT_EQUALS_OPERATOR, false, true, false, false, false);
                break;
            }
        case NOT_NULL:
            {
                buildExpression(sb, entityKey, field, new Object[] { "null" }, type, secondaryType, NOT_EQUALS_OPERATOR, false, false, false, false, true);
                break;
            }
        case NOT_STARTS_WITH:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, STARTS_WITH_OPERATOR, true, false, false, true, false);
                break;
            }
        case STARTS_WITH:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, STARTS_WITH_OPERATOR, true, false, false, false, false);
                break;
            }
        case STARTS_WITH_FIELD:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, STARTS_WITH_OPERATOR, true, true, false, false, false);
                break;
            }
        case COUNT_GREATER_THAN:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, SIZE_GREATER_THAN_OPERATOR, false, false, false, false, true);
                break;
            }
        case COUNT_GREATER_OR_EQUAL:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, SIZE_GREATER_THAN_EQUALS_OPERATOR, false, false, false, false, true);
                break;
            }
        case COUNT_LESS_THAN:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, SIZE_LESS_THAN_OPERATOR, false, false, false, false, true);
                break;
            }
        case COUNT_LESS_OR_EQUAL:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, SIZE_LESS_THAN_EQUALS_OPERATOR, false, false, false, false, true);
                break;
            }
        case COUNT_EQUALS:
            {
                buildExpression(sb, entityKey, field, value, type, secondaryType, SIZE_EQUALS_OPERATOR, false, false, false, false, true);
                break;
            }
        case COLLECTION_IN:
            {
                buildCollectionExpression(sb, entityKey, field, value, type, secondaryType, SIZE_GREATER_THAN_OPERATOR + ZERO_OPERATOR, false, false, false, false, true);
                break;
            }
        case COLLECTION_NOT_IN:
            {
                buildCollectionExpression(sb, entityKey, field, value, type, secondaryType, SIZE_EQUALS_OPERATOR + ZERO_OPERATOR, false, false, false, false, true);
                break;
            }
        case BETWEEN:
            {
                if (value != null && value.length == 2) {
                    sb.append("(");
                    buildExpression(sb, entityKey, field, new Object[] { value[0] }, type, secondaryType, GREATER_THAN_OPERATOR, false, false, false, false, true);
                    sb.append("&&");
                    buildExpression(sb, entityKey, field, new Object[] { value[1] }, type, secondaryType, LESS_THAN_OPERATOR, false, false, false, false, true);
                    sb.append(")");
                }
                break;
            }
        case BETWEEN_INCLUSIVE:
            {
                if (value != null && value.length == 2) {
                    sb.append("(");
                    buildExpression(sb, entityKey, field, new Object[] { value[0] }, type, secondaryType, GREATER_THAN_EQUALS_OPERATOR, false, false, false, false, true);
                    sb.append("&&");
                    buildExpression(sb, entityKey, field, new Object[] { value[1] }, type, secondaryType, LESS_THAN_EQUALS_OPERATOR, false, false, false, false, true);
                    sb.append(")");
                }
                break;
            }
    }
}
Also used : SupportedFieldType(org.broadleafcommerce.common.presentation.client.SupportedFieldType)

Example 4 with SupportedFieldType

use of org.broadleafcommerce.common.presentation.client.SupportedFieldType in project BroadleafCommerce by BroadleafCommerce.

the class MVELToDataWrapperTranslator method appendExpression.

public void appendExpression(String phrase, RuleBuilderFieldService fieldService, DataDTO parentDTO, List<ExpressionDTO> myCriteriaList) throws MVELTranslationException {
    Expression expression = phraseTranslator.createExpression(phrase);
    FieldDTO field = fieldService.getField(expression.getField());
    if (field == null) {
        throw new MVELTranslationException(MVELTranslationException.SPECIFIED_FIELD_NOT_FOUND, "MVEL phrase is not " + "compatible with the RuleBuilderFieldService associated with the current rules builder. " + "Unable to find the field specified: (" + expression.getField() + ")");
    }
    SupportedFieldType type = fieldService.getSupportedFieldType(expression.getField());
    ExpressionDTO expressionDTO = createExpressionDTO(expression);
    postProcessCriteria(parentDTO, myCriteriaList, expressionDTO, type);
}
Also used : SupportedFieldType(org.broadleafcommerce.common.presentation.client.SupportedFieldType) Expression(org.broadleafcommerce.openadmin.web.rulebuilder.statement.Expression) FieldDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Aggregations

SupportedFieldType (org.broadleafcommerce.common.presentation.client.SupportedFieldType)4 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)2 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)2 AddMetadataFromFieldTypeRequest (org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.AddMetadataFromFieldTypeRequest)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Map (java.util.Map)1 AdminPresentationMap (org.broadleafcommerce.common.presentation.AdminPresentationMap)1 FieldMetadataOverride (org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)1 ExpressionDTO (org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)1 FieldDTO (org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO)1 Expression (org.broadleafcommerce.openadmin.web.rulebuilder.statement.Expression)1 TypeLocatorImpl (org.hibernate.internal.TypeLocatorImpl)1 Type (org.hibernate.type.Type)1 TypeResolver (org.hibernate.type.TypeResolver)1