Search in sources :

Example 11 with ExpressionDTO

use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO in project BroadleafCommerce by BroadleafCommerce.

the class MVELToDataWrapperTranslator method postProcessCriteria.

protected void postProcessCriteria(DataDTO parentDTO, List<ExpressionDTO> myCriteriaList, ExpressionDTO temp, SupportedFieldType type) {
    int lstIdx = myCriteriaList.size() - 1;
    ExpressionDTO prevExpression = lstIdx != -1 ? myCriteriaList.get(lstIdx) : null;
    boolean sameExpressionId = prevExpression != null && temp.getId().equals(prevExpression.getId());
    if (sameExpressionId && isBetweenOperator(prevExpression, temp)) {
        prevExpression.setOperator(BLCOperator.BETWEEN.name());
        boolean hasTempSmallerVal = Long.parseLong(temp.getValue()) < Long.parseLong(prevExpression.getValue());
        String start = hasTempSmallerVal ? temp.getValue() : prevExpression.getValue();
        String end = hasTempSmallerVal ? prevExpression.getValue() : temp.getValue();
        if (type.toString().equals(SupportedFieldType.DATE.toString())) {
            start = "\"" + start + "\"";
            end = "\"" + end + "\"";
        }
        prevExpression.setValue("[" + start + "," + end + "]");
        if (parentDTO != null) {
            parentDTO.getRules().add(myCriteriaList.remove(lstIdx));
        }
    } else if (sameExpressionId && isBetweenInclusiveOperator(prevExpression, temp)) {
        prevExpression.setOperator(BLCOperator.BETWEEN_INCLUSIVE.name());
        boolean hasTempSmallerVal = Long.parseLong(temp.getValue()) < Long.parseLong(prevExpression.getValue());
        String start = hasTempSmallerVal ? temp.getValue() : prevExpression.getValue();
        String end = hasTempSmallerVal ? prevExpression.getValue() : temp.getValue();
        if (type.toString().equals(SupportedFieldType.DATE.toString())) {
            start = "\"" + start + "\"";
            end = "\"" + end + "\"";
        }
        prevExpression.setValue("[" + start + "," + end + "]");
        if (parentDTO != null) {
            parentDTO.getRules().add(myCriteriaList.remove(lstIdx));
        }
    } else if (isProjection(temp.getValue())) {
        if (parentDTO != null) {
            parentDTO.getRules().add(temp);
        } else {
            myCriteriaList.add(temp);
        }
    } else {
        myCriteriaList.add(temp);
    }
}
Also used : ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 12 with ExpressionDTO

use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO in project BroadleafCommerce by BroadleafCommerce.

the class MVELToDataWrapperTranslator method checkForInvalidSubGroup.

protected Boolean checkForInvalidSubGroup(DataDTO dataDTO) {
    Boolean invalidSubGroupFound = false;
    for (DataDTO rules : dataDTO.getRules()) {
        ArrayList<DataDTO> subRules = rules.getRules();
        if (subRules != null && subRules.size() == 2) {
            ExpressionDTO expression1 = (ExpressionDTO) subRules.get(0);
            ExpressionDTO expression2 = (ExpressionDTO) subRules.get(1);
            Boolean isBetweenDetected = false;
            Boolean isBetweenInclusiveDetected = false;
            if (expression1.getOperator().equals("GREATER_THAN") && expression2.getOperator().equals("LESS_THAN")) {
                isBetweenDetected = true;
            }
            if (expression1.getOperator().equals("GREATER_OR_EQUAL") && expression2.getOperator().equals("LESS_OR_EQUAL")) {
                isBetweenInclusiveDetected = true;
            }
            if (!isBetweenDetected && !isBetweenInclusiveDetected) {
                invalidSubGroupFound = true;
            }
        } else {
            invalidSubGroupFound = true;
        }
    }
    return invalidSubGroupFound;
}
Also used : DataDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 13 with ExpressionDTO

use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO in project BroadleafCommerce by BroadleafCommerce.

the class DataDTOToMVELTranslator method buildMVEL.

protected void buildMVEL(DataDTO dataDTO, StringBuffer sb, String entityKey, String groupOperator, RuleBuilderFieldService fieldService) throws MVELTranslationException {
    BLCOperator operator = null;
    if (dataDTO instanceof ExpressionDTO) {
        operator = BLCOperator.valueOf(((ExpressionDTO) dataDTO).getOperator());
    } else {
        operator = BLCOperator.valueOf(dataDTO.getCondition());
    }
    ArrayList<DataDTO> groups = dataDTO.getRules();
    if (sb.length() != 0 && sb.charAt(sb.length() - 1) != '(' && groupOperator != null) {
        BLCOperator groupOp = BLCOperator.valueOf(groupOperator);
        switch(groupOp) {
            default:
                sb.append("&&");
                break;
            case OR:
                sb.append("||");
        }
    }
    if (dataDTO instanceof ExpressionDTO) {
        buildExpression((ExpressionDTO) dataDTO, sb, entityKey, operator, fieldService);
    } else {
        boolean includeTopLevelParenthesis = false;
        if (sb.length() != 0 || BLCOperator.NOT.equals(operator) || (sb.length() == 0 && groupOperator != null)) {
            includeTopLevelParenthesis = true;
        }
        if (BLCOperator.NOT.equals(operator)) {
            sb.append("!");
        }
        if (includeTopLevelParenthesis)
            sb.append("(");
        for (DataDTO dto : groups) {
            buildMVEL(dto, sb, entityKey, dataDTO.getCondition(), fieldService);
        }
        if (includeTopLevelParenthesis)
            sb.append(")");
    }
}
Also used : DataDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 14 with ExpressionDTO

use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO in project BroadleafCommerce by BroadleafCommerce.

the class MVELToDataWrapperTranslator method createRuleDataDTO.

protected DataDTO createRuleDataDTO(DataDTO parentDTO, Group group, RuleBuilderFieldService fieldService) throws MVELTranslationException {
    DataDTO data = new DataDTO();
    if (group.getOperatorType() == null) {
        group.setOperatorType(BLCOperator.AND);
    }
    BLCOperator operator = group.getOperatorType();
    data.setCondition(operator.name());
    List<ExpressionDTO> myCriteriaList = new ArrayList<ExpressionDTO>();
    if (BLCOperator.NOT.equals(group.getOperatorType()) && group.getIsTopGroup()) {
        group = group.getSubGroups().get(0);
        group.setOperatorType(operator);
    }
    for (String phrase : group.getPhrases()) {
        appendExpression(phrase, fieldService, parentDTO, myCriteriaList);
    }
    if (!myCriteriaList.isEmpty()) {
        data.getRules().addAll(myCriteriaList);
    }
    for (Group subgroup : group.getSubGroups()) {
        DataDTO subCriteria = createRuleDataDTO(data, subgroup, fieldService);
        if (subCriteria != null && !subCriteria.getRules().isEmpty()) {
            data.getRules().add(subCriteria);
        }
    }
    if (data.getRules() != null && !data.getRules().isEmpty()) {
        return data;
    } else {
        return null;
    }
}
Also used : Group(org.broadleafcommerce.openadmin.web.rulebuilder.grouping.Group) DataDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO) ArrayList(java.util.ArrayList) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 15 with ExpressionDTO

use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO in project BroadleafCommerce by BroadleafCommerce.

the class MVELToDataWrapperTranslator method createExpressionDTO.

public ExpressionDTO createExpressionDTO(Expression expression) {
    ExpressionDTO expressionDTO = new ExpressionDTO();
    expressionDTO.setId(expression.getField());
    expressionDTO.setOperator(expression.getOperator().name());
    expressionDTO.setValue(expression.getValue());
    return expressionDTO;
}
Also used : ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Aggregations

ExpressionDTO (org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)20 Entity (org.broadleafcommerce.openadmin.dto.Entity)8 Property (org.broadleafcommerce.openadmin.dto.Property)8 MVELToDataWrapperTranslator (org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator)8 DataDTO (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO)8 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)8 DataDTOToMVELTranslator (org.broadleafcommerce.openadmin.web.rulebuilder.DataDTOToMVELTranslator)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 CollectionType (com.fasterxml.jackson.databind.type.CollectionType)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 SupportedFieldType (org.broadleafcommerce.common.presentation.client.SupportedFieldType)1 FieldDTO (org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO)1 Group (org.broadleafcommerce.openadmin.web.rulebuilder.grouping.Group)1 Expression (org.broadleafcommerce.openadmin.web.rulebuilder.statement.Expression)1