Search in sources :

Example 26 with Property

use of org.broadleafcommerce.openadmin.dto.Property 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 27 with Property

use of org.broadleafcommerce.openadmin.dto.Property 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)

Example 28 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class MVELToDataWrapperTranslatorTest method testNestedExpressionExceptionForFulfillmentGroupQualificationDataWrapper.

public void testNestedExpressionExceptionForFulfillmentGroupQualificationDataWrapper() 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.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 29 with Property

use of org.broadleafcommerce.openadmin.dto.Property 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 30 with Property

use of org.broadleafcommerce.openadmin.dto.Property 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)

Aggregations

Property (org.broadleafcommerce.openadmin.dto.Property)120 Entity (org.broadleafcommerce.openadmin.dto.Entity)62 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)45 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)38 ArrayList (java.util.ArrayList)28 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)26 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)25 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)21 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)19 HashMap (java.util.HashMap)18 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)18 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)16 Map (java.util.Map)15 ServiceException (org.broadleafcommerce.common.exception.ServiceException)15 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)15 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)13 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)12 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)12