Search in sources :

Example 6 with ExpressionDTO

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

the class MVELToDataWrapperTranslatorTest method testFulfillmentGroupQualificationDataWrapper.

public void testFulfillmentGroupQualificationDataWrapper() throws MVELTranslationException {
    MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
    Property[] properties = new Property[1];
    Property mvelProperty = new Property();
    mvelProperty.setName("matchRule");
    mvelProperty.setValue("fulfillmentGroup.address.state.name==\"Texas\"&&fulfillmentGroup.retailFulfillmentPrice.getAmount()>=99&&fulfillmentGroup.retailFulfillmentPrice.getAmount()<=199");
    properties[0] = mvelProperty;
    Entity[] entities = new Entity[1];
    Entity entity = new Entity();
    entity.setProperties(properties);
    entities[0] = entity;
    DataWrapper dataWrapper = translator.createRuleData(entities, "matchRule", null, null, fulfillmentGroupFieldService);
    assert (dataWrapper.getData().size() == 1);
    assert (dataWrapper.getData().get(0).getQuantity() == null);
    assert (dataWrapper.getData().get(0).getCondition().equals(BLCOperator.AND.name()));
    assert (dataWrapper.getData().get(0).getRules().size() == 2);
    assert (dataWrapper.getData().get(0).getRules().get(0) instanceof ExpressionDTO);
    ExpressionDTO e1 = (ExpressionDTO) dataWrapper.getData().get(0).getRules().get(0);
    assert (e1.getId().equals("address.state.name"));
    assert (e1.getOperator().equals(BLCOperator.EQUALS.name()));
    assert (e1.getValue().equals("Texas"));
    assert (dataWrapper.getData().get(0).getRules().get(1) instanceof ExpressionDTO);
    ExpressionDTO e2 = (ExpressionDTO) dataWrapper.getData().get(0).getRules().get(1);
    assert (e2.getId().equals("retailFulfillmentPrice"));
    assert (e2.getOperator().equals(BLCOperator.BETWEEN_INCLUSIVE.name()));
    assert (e2.getValue().equals("[99,199]"));
}
Also used : DataWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper) Entity(org.broadleafcommerce.openadmin.dto.Entity) MVELToDataWrapperTranslator(org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator) Property(org.broadleafcommerce.openadmin.dto.Property) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 7 with ExpressionDTO

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

the class MVELToDataWrapperTranslatorTest method testCustomerQualificationDataWrapper.

public void testCustomerQualificationDataWrapper() throws MVELTranslationException {
    MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
    Property[] properties = new Property[1];
    Property mvelProperty = new Property();
    mvelProperty.setName("matchRule");
    mvelProperty.setValue("customer.emailAddress!=customer.username");
    properties[0] = mvelProperty;
    Entity[] entities = new Entity[1];
    Entity entity = new Entity();
    entity.setProperties(properties);
    entities[0] = entity;
    DataWrapper dataWrapper = translator.createRuleData(entities, "matchRule", null, null, customerFieldService);
    assert (dataWrapper.getData().size() == 1);
    assert (dataWrapper.getData().get(0).getQuantity() == null);
    assert (dataWrapper.getData().get(0).getCondition().equals(BLCOperator.AND.name()));
    assert (dataWrapper.getData().get(0).getRules().get(0) instanceof ExpressionDTO);
    ExpressionDTO e1 = (ExpressionDTO) dataWrapper.getData().get(0).getRules().get(0);
    assert (e1.getId().equals("emailAddress"));
    assert (e1.getOperator().equals(BLCOperator.NOT_EQUAL_FIELD.name()));
    assert (e1.getValue().equals("username"));
}
Also used : DataWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper) Entity(org.broadleafcommerce.openadmin.dto.Entity) MVELToDataWrapperTranslator(org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator) Property(org.broadleafcommerce.openadmin.dto.Property) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 8 with ExpressionDTO

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

the class MVELToDataWrapperTranslatorTest method testItemQualificationDataWrapper.

public void testItemQualificationDataWrapper() throws MVELTranslationException {
    MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
    Property[] p1 = new Property[3];
    Property m1 = new Property();
    m1.setName("orderItemMatchRule");
    m1.setValue("discreteOrderItem.category.name==\"test category\"");
    Property q1 = new Property();
    q1.setName("quantity");
    q1.setValue("1");
    Property i1 = new Property();
    i1.setName("id");
    i1.setValue("100");
    p1[0] = m1;
    p1[1] = q1;
    p1[2] = i1;
    Entity e1 = new Entity();
    e1.setProperties(p1);
    Property[] p2 = new Property[3];
    Property m2 = new Property();
    m2.setName("orderItemMatchRule");
    m2.setValue("CollectionUtils.intersection(orderItem.?product.?manufacturer,[\"test manufacturer\"]).size()==0");
    Property q2 = new Property();
    q2.setName("quantity");
    q2.setValue("2");
    Property i2 = new Property();
    i2.setName("id");
    i2.setValue("200");
    p2[0] = m2;
    p2[1] = q2;
    p2[2] = i2;
    Entity e2 = new Entity();
    e2.setProperties(p2);
    Entity[] entities = new Entity[2];
    entities[0] = e1;
    entities[1] = e2;
    DataWrapper dataWrapper = translator.createRuleData(entities, "orderItemMatchRule", "quantity", "id", orderItemFieldService);
    assert (dataWrapper.getData().size() == 2);
    assert (dataWrapper.getData().get(0).getQuantity() == 1);
    assert (dataWrapper.getData().get(0).getCondition().equals(BLCOperator.AND.name()));
    assert (dataWrapper.getData().get(0).getRules().size() == 1);
    assert (dataWrapper.getData().get(0).getRules().get(0) instanceof ExpressionDTO);
    ExpressionDTO exp1 = (ExpressionDTO) dataWrapper.getData().get(0).getRules().get(0);
    assert (exp1.getId().equals("category.name"));
    assert (exp1.getOperator().equals(BLCOperator.EQUALS.name()));
    assert (exp1.getValue().equals("test category"));
    assert (dataWrapper.getData().get(1).getQuantity() == 2);
    assert (dataWrapper.getData().get(1).getRules().get(0) instanceof ExpressionDTO);
    ExpressionDTO expd1e1 = (ExpressionDTO) dataWrapper.getData().get(1).getRules().get(0);
    assert (expd1e1.getId().equals("product.manufacturer"));
    assert (expd1e1.getOperator().equals(BLCOperator.COLLECTION_NOT_IN.name()));
    assert (expd1e1.getValue().equals("[\"test manufacturer\"]"));
}
Also used : DataWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper) Entity(org.broadleafcommerce.openadmin.dto.Entity) MVELToDataWrapperTranslator(org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator) Property(org.broadleafcommerce.openadmin.dto.Property) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 9 with ExpressionDTO

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

the class DataDTODeserializer method deserialize.

@Override
public DataDTO deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    ObjectNode root = (ObjectNode) mapper.readTree(jp);
    Iterator<Map.Entry<String, JsonNode>> elementsIterator = root.fields();
    DataDTO dataDTO = new DataDTO();
    ExpressionDTO expressionDTO = new ExpressionDTO();
    boolean isExpression = false;
    while (elementsIterator.hasNext()) {
        Map.Entry<String, JsonNode> element = elementsIterator.next();
        String name = element.getKey();
        if ("id".equals(name)) {
            expressionDTO.setId(getNullAwareText(element.getValue()));
            isExpression = true;
        }
        if ("operator".equals(name)) {
            expressionDTO.setOperator(getNullAwareText(element.getValue()));
            isExpression = true;
        }
        if ("value".equals(name)) {
            expressionDTO.setValue(getNullAwareText(element.getValue()));
            isExpression = true;
        }
        if ("pk".equals(name)) {
            if (getNullAwareText(element.getValue()) == null || StringUtils.isBlank(element.getValue().asText())) {
                dataDTO.setPk(null);
            } else {
                dataDTO.setPk(element.getValue().asLong());
            }
        }
        if ("previousPk".equals(name)) {
            if (getNullAwareText(element.getValue()) == null || StringUtils.isBlank(element.getValue().asText())) {
                dataDTO.setPreviousPk(null);
            } else {
                dataDTO.setPreviousPk(element.getValue().asLong());
            }
        }
        if ("containedPk".equals(name)) {
            if (getNullAwareText(element.getValue()) == null || StringUtils.isBlank(element.getValue().asText())) {
                dataDTO.setContainedPk(null);
            } else {
                dataDTO.setContainedPk(element.getValue().asLong());
            }
        }
        if ("previousContainedPk".equals(name)) {
            if (getNullAwareText(element.getValue()) == null || StringUtils.isBlank(element.getValue().asText())) {
                dataDTO.setPreviousContainedPk(null);
            } else {
                dataDTO.setPreviousContainedPk(element.getValue().asLong());
            }
        }
        if ("quantity".equals(name)) {
            if (getNullAwareText(element.getValue()) == null) {
                dataDTO.setQuantity(null);
            } else {
                dataDTO.setQuantity(element.getValue().asInt());
            }
        }
        if ("condition".equals(name)) {
            dataDTO.setCondition(getNullAwareText(element.getValue()));
        }
        if ("rules".equals(name)) {
            CollectionType dtoCollectionType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, DataDTO.class);
            dataDTO.setRules((ArrayList<DataDTO>) mapper.readValue(element.getValue().traverse(jp.getCodec()), dtoCollectionType));
        }
    }
    if (isExpression) {
        return expressionDTO;
    } else {
        return dataDTO;
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) DataDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 10 with ExpressionDTO

use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO 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

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