Search in sources :

Example 16 with ExpressionDTO

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

the class DataDTOToMVELTranslatorTest method testItemQualificationMVEL.

/**
 * Tests the creation of an Item Qualification MVEL expression from a DataDTO
 * @throws MVELTranslationException
 *
 * [{"pk":100,
 *  "quantity":1,
 *  "condition":"AND",
 *  "rules":[
 *      {"pk":null,
 *      "quantity":null,
 *      "condition":null,
 *      "rules":null,
 *      "id":"category.name",
 *      "operator":"EQUALS",
 *      "value":"test category"
 *      }]
 *  },
 *  {"pk":"200",
 *  "quantity":2,
 *  "condition":"NOT",
 *  "rules":[
 *      {"pk":null,
 *      "quantity":null,
 *      "condition":null,
 *      "rules":null,
 *      "id":"product.manufacturer",
 *      "operator":"EQUALS",
 *      "value":"test manufacturer"}]
 *  }]
 */
public void testItemQualificationMVEL() throws MVELTranslationException {
    DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator();
    DataDTO d1 = new DataDTO();
    d1.setQuantity(1);
    d1.setCondition(BLCOperator.AND.name());
    ExpressionDTO d1e1 = new ExpressionDTO();
    d1e1.setId("category.name");
    d1e1.setOperator(BLCOperator.EQUALS.name());
    d1e1.setValue("test category");
    d1.getRules().add(d1e1);
    String d1Translated = translator.createMVEL("discreteOrderItem", d1, orderItemFieldService);
    String d1Mvel = "discreteOrderItem.?category.?name==\"test category\"";
    assert (d1Mvel.equals(d1Translated));
    DataDTO d2 = new DataDTO();
    d2.setQuantity(1);
    d2.setCondition(BLCOperator.NOT.name());
    ExpressionDTO d2e1 = new ExpressionDTO();
    d2e1.setId("product.manufacturer");
    d2e1.setOperator(BLCOperator.EQUALS.name());
    d2e1.setValue("test manufacturer");
    d2.getRules().add(d2e1);
    String d2Translated = translator.createMVEL("discreteOrderItem", d2, orderItemFieldService);
    String d2Mvel = "!(discreteOrderItem.?product.?manufacturer==\"test manufacturer\")";
    assert (d2Mvel.equals(d2Translated));
}
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 17 with ExpressionDTO

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

the class DataDTOToMVELTranslatorTest method testItemQualificationCollectionMVEL.

public void testItemQualificationCollectionMVEL() throws MVELTranslationException {
    DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator();
    DataDTO d1 = new DataDTO();
    d1.setQuantity(1);
    d1.setCondition(BLCOperator.AND.name());
    ExpressionDTO d1e1 = new ExpressionDTO();
    d1e1.setId("category.name");
    d1e1.setOperator(BLCOperator.COLLECTION_IN.name());
    d1e1.setValue("[\"test category\", \"test category 2\"]");
    d1.getRules().add(d1e1);
    String d1Translated = translator.createMVEL("discreteOrderItem", d1, orderItemFieldService);
    String d1Mvel = "CollectionUtils.intersection(discreteOrderItem.?category.?name,[\"test category\", \"test category 2\"]).size()>0";
    assert (d1Mvel.equals(d1Translated));
}
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 18 with ExpressionDTO

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

the class MVELToDataWrapperTranslatorTest method testInBetweenRuleOrderGreaterThenAndLessThenAndCurrency.

public void testInBetweenRuleOrderGreaterThenAndLessThenAndCurrency() throws MVELTranslationException {
    MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
    Property[] properties = new Property[3];
    Property mvelProperty = new Property();
    mvelProperty.setName("orderMatchRule");
    mvelProperty.setValue("order.?subTotal.getAmount()>45&&order.?subTotal.getAmount()<75&&order.?currency.?currencyCode==\"USD\"");
    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, "orderMatchRule", "quantity", "id", orderFieldService);
    assert (dataWrapper.getData().size() == 1);
    assert (dataWrapper.getData().get(0).getQuantity() == 1);
    assert (dataWrapper.getData().get(0).getRules().size() == 2);
    assert (dataWrapper.getData().get(0).getRules().get(0) instanceof ExpressionDTO);
    ExpressionDTO exp = (ExpressionDTO) dataWrapper.getData().get(0).getRules().get(0);
    assert (exp.getId().equals("subTotal"));
    assert (exp.getOperator().equals(BLCOperator.BETWEEN.name()));
    assert (exp.getValue().equals("[45,75]"));
}
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 19 with ExpressionDTO

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

the class MVELToDataWrapperTranslatorTest method testItemQualificationCollectionDataWrapper.

public void testItemQualificationCollectionDataWrapper() throws MVELTranslationException {
    MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
    Property[] p1 = new Property[3];
    Property m1 = new Property();
    m1.setName("orderItemMatchRule");
    m1.setValue("CollectionUtils.intersection(discreteOrderItem.?category.?name,[\"test category\", \"test category 2\"]).size()>0&&discreteOrderItem.?quantity>5");
    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() == 2);
    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.COLLECTION_IN.name()));
    assert (exp1.getValue().equals("[\"test category\", \"test category 2\"]"));
    assert (dataWrapper.getData().get(0).getRules().get(1) instanceof ExpressionDTO);
    ExpressionDTO exp2 = (ExpressionDTO) dataWrapper.getData().get(0).getRules().get(1);
    assert (exp2.getId().equals("quantity"));
    assert (exp2.getOperator().equals(BLCOperator.GREATER_THAN.name()));
    assert (exp2.getValue().equals("5"));
    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 20 with ExpressionDTO

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

the class MVELToDataWrapperTranslatorTest method testInBetweenRuleOrderLessThenAndGreaterThenAndCurrency.

public void testInBetweenRuleOrderLessThenAndGreaterThenAndCurrency() throws MVELTranslationException {
    MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
    Property[] properties = new Property[3];
    Property mvelProperty = new Property();
    mvelProperty.setName("orderMatchRule");
    mvelProperty.setValue("order.?subTotal.getAmount()<75&&order.?subTotal.getAmount()>45&&order.?currency.?currencyCode==\"USD\"");
    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, "orderMatchRule", "quantity", "id", orderFieldService);
    assert (dataWrapper.getData().size() == 1);
    assert (dataWrapper.getData().get(0).getQuantity() == 1);
    assert (dataWrapper.getData().get(0).getRules().size() == 2);
    assert (dataWrapper.getData().get(0).getRules().get(0) instanceof ExpressionDTO);
    ExpressionDTO exp = (ExpressionDTO) dataWrapper.getData().get(0).getRules().get(0);
    assert (exp.getId().equals("subTotal"));
    assert (exp.getOperator().equals(BLCOperator.BETWEEN.name()));
    assert (exp.getValue().equals("[45,75]"));
}
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