Search in sources :

Example 1 with ExpressionDTO

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

the class DataDTOToMVELTranslatorTest method testCreateMVEL.

/**
 * Tests the creation of an MVEL expression from a DataDTO
 * @throws MVELTranslationException
 *
 * Here's an example of a DataWrapper with a single DataDTO
 *
 * [{"pk":"100",
 *  "quantity":"1",
 *  "condition":"AND",
 *  "rules":[
 *      {"pk":null,
 *      "quantity":null,
 *      "condition":null,
 *      "rules":null,
 *      "id":"category.name",
 *      "operator":"IEQUALS",
 *      "value":"merchandise"}]
 *  }]
 */
public void testCreateMVEL() throws MVELTranslationException {
    DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator();
    ExpressionDTO expressionDTO = new ExpressionDTO();
    expressionDTO.setId("category.name");
    expressionDTO.setOperator(BLCOperator.IEQUALS.name());
    expressionDTO.setValue("merchandise");
    String translated = translator.createMVEL("discreteOrderItem", expressionDTO, orderItemFieldService);
    String mvel = "MvelHelper.toUpperCase(discreteOrderItem.?category.?name)==MvelHelper.toUpperCase(\"merchandise\")";
    assert (mvel.equals(translated));
}
Also used : DataDTOToMVELTranslator(org.broadleafcommerce.openadmin.web.rulebuilder.DataDTOToMVELTranslator) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 2 with ExpressionDTO

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

the class DataDTOToMVELTranslatorTest method testFulfillmentQualificationMVEL.

/**
 * Tests the creation of a Fulfillment Group Qualification MVEL expression from a DataDTO
 * @throws MVELTranslationException
 *
 * [{"pk":null,
 *  "quantity":null,
 *  "condition":"AND",
 *  "rules":[
 *      {"pk":null,
 *      "quantity":null,
 *      "condition":null,
 *      "rules":null,
 *      "id":"address.state.name",
 *      "operator":"EQUALS",
 *      "value":["Texas"]},
 *      {"pk":null,
 *      "quantity":null,
 *      "condition":null,
 *      "rules":null,
 *      "id":"retailShippingPrice",
 *      "operator":"BETWEEN_INCLUSIVE",
 *      "value":"[99,199]"}]
 *  }]
 */
public void testFulfillmentQualificationMVEL() throws MVELTranslationException {
    DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator();
    DataDTO dataDTO = new DataDTO();
    dataDTO.setCondition(BLCOperator.AND.name());
    ExpressionDTO e1 = new ExpressionDTO();
    e1.setId("address.state.name");
    e1.setOperator(BLCOperator.EQUALS.name());
    e1.setValue("Texas");
    ExpressionDTO e2 = new ExpressionDTO();
    e2.setId("retailFulfillmentPrice");
    e2.setOperator(BLCOperator.BETWEEN_INCLUSIVE.name());
    e2.setValue("[99,199]");
    dataDTO.getRules().add(e1);
    dataDTO.getRules().add(e2);
    String translated = translator.createMVEL("fulfillmentGroup", dataDTO, fulfillmentGroupFieldService);
    String mvel = "fulfillmentGroup.?address.?state.?name==\"Texas\"&&(fulfillmentGroup.?retailFulfillmentPrice.getAmount()>=99&&fulfillmentGroup.?retailFulfillmentPrice.getAmount()<=199)";
    assert (mvel.equals(translated));
}
Also used : DataDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO) DataDTOToMVELTranslator(org.broadleafcommerce.openadmin.web.rulebuilder.DataDTOToMVELTranslator) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 3 with ExpressionDTO

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

the class DataDTOToMVELTranslatorTest method testOrderQualificationMVEL.

/**
 * Tests the creation of an Order Qualification MVEL expression from a DataDTO
 * @throws MVELTranslationException
 *
 * [{"pk":null,
 *  "quantity":null,
 *  "condition":"AND",
 *  "rules":[
 *      {"pk":null,
 *      "quantity":null,
 *      "condition":null,
 *      "rules":null,
 *      "id":"subTotal",
 *      "operator":"GREATER_OR_EQUAL",
 *      "value":"100"}]
 *  }]
 */
public void testOrderQualificationMVEL() throws MVELTranslationException {
    DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator();
    DataDTO dataDTO = new DataDTO();
    dataDTO.setCondition(BLCOperator.AND.name());
    ExpressionDTO expressionDTO = new ExpressionDTO();
    expressionDTO.setId("subTotal");
    expressionDTO.setOperator(BLCOperator.GREATER_OR_EQUAL.name());
    expressionDTO.setValue("100");
    dataDTO.getRules().add(expressionDTO);
    String translated = translator.createMVEL("order", dataDTO, orderFieldService);
    String mvel = "order.?subTotal.getAmount()>=100";
    assert (mvel.equals(translated));
}
Also used : DataDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO) DataDTOToMVELTranslator(org.broadleafcommerce.openadmin.web.rulebuilder.DataDTOToMVELTranslator) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 4 with ExpressionDTO

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

the class MVELToDataWrapperTranslatorTest method testCreateRuleData.

/**
 * Tests the creation of a DataWrapper given an mvel/quantity property
 * @throws MVELTranslationException
 */
public void testCreateRuleData() throws MVELTranslationException {
    MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
    Property[] properties = new Property[3];
    Property mvelProperty = new Property();
    mvelProperty.setName("orderItemMatchRule");
    mvelProperty.setValue("MVEL.eval(\"toUpperCase()\",discreteOrderItem.?category.?name)==MVEL.eval(\"toUpperCase()\",\"merchandise\")");
    Property quantityProperty = new Property();
    quantityProperty.setName("quantity");
    quantityProperty.setValue("1");
    Property idProperty = new Property();
    idProperty.setName("id");
    idProperty.setValue("100");
    properties[0] = mvelProperty;
    properties[1] = quantityProperty;
    properties[2] = idProperty;
    Entity[] entities = new Entity[1];
    Entity entity = new Entity();
    entity.setProperties(properties);
    entities[0] = entity;
    DataWrapper dataWrapper = translator.createRuleData(entities, "orderItemMatchRule", "quantity", "id", orderItemFieldService);
    assert (dataWrapper.getData().size() == 1);
    assert (dataWrapper.getData().get(0).getQuantity() == 1);
    assert (dataWrapper.getData().get(0).getRules().size() == 1);
    assert (dataWrapper.getData().get(0).getRules().get(0) instanceof ExpressionDTO);
    ExpressionDTO exp = (ExpressionDTO) dataWrapper.getData().get(0).getRules().get(0);
    assert (exp.getId().equals("category.name"));
    assert (exp.getOperator().equals(BLCOperator.IEQUALS.name()));
    assert (exp.getValue().equals("merchandise"));
}
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 5 with ExpressionDTO

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

the class MVELToDataWrapperTranslatorTest method testOrderQualificationDataWrapper.

public void testOrderQualificationDataWrapper() throws MVELTranslationException {
    MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
    Property[] properties = new Property[1];
    Property mvelProperty = new Property();
    mvelProperty.setName("matchRule");
    mvelProperty.setValue("order.subTotal.getAmount()>=100");
    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, orderFieldService);
    assert (dataWrapper.getData().size() == 1);
    assert (dataWrapper.getData().get(0).getQuantity() == null);
    assert (dataWrapper.getData().get(0).getRules().get(0) instanceof ExpressionDTO);
    ExpressionDTO e1 = (ExpressionDTO) dataWrapper.getData().get(0).getRules().get(0);
    assert (e1.getId().equals("subTotal"));
    assert (e1.getOperator().equals(BLCOperator.GREATER_OR_EQUAL.name()));
    assert (e1.getValue().equals("100"));
}
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)

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