Search in sources :

Example 16 with DataWrapper

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

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

the class MVELToDataWrapperTranslatorTest method testNestedExpressionExceptionForItemQualificationCollectionDataWrapper.

public void testNestedExpressionExceptionForItemQualificationCollectionDataWrapper() 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("!(discreteOrderItem.product.manufacturer==\"test manufacturer\")");
    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.getError().equals(MVELToDataWrapperTranslator.SUB_GROUP_MESSAGE));
}
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)

Example 18 with DataWrapper

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

the class MVELToDataWrapperTranslatorTest method testNestedExpressionExceptionForItemQualificationDataWrapper.

public void testNestedExpressionExceptionForItemQualificationDataWrapper() 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("!(discreteOrderItem.product.manufacturer==\"test manufacturer\")");
    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.getError().equals(MVELToDataWrapperTranslator.SUB_GROUP_MESSAGE));
}
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)

Example 19 with DataWrapper

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

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

DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)24 Property (org.broadleafcommerce.openadmin.dto.Property)21 Entity (org.broadleafcommerce.openadmin.dto.Entity)16 MVELToDataWrapperTranslator (org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator)12 ExpressionDTO (org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)8 MVELTranslationException (org.broadleafcommerce.openadmin.web.rulebuilder.MVELTranslationException)6 FieldNotAvailableException (org.broadleafcommerce.openadmin.server.service.persistence.module.FieldNotAvailableException)5 ArrayList (java.util.ArrayList)4 EntityManager (javax.persistence.EntityManager)4 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)4 ParentEntityPersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.ParentEntityPersistenceException)4 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)4 MediaField (org.broadleafcommerce.openadmin.web.form.component.MediaField)4 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)4 CodeField (org.broadleafcommerce.openadmin.web.form.entity.CodeField)4 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)4 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)4 QuantityBasedRule (org.broadleafcommerce.common.rule.QuantityBasedRule)3 DataDTO (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2