Search in sources :

Example 1 with MVELToDataWrapperTranslator

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

the class RuleFieldPersistenceProvider method extractValue.

@Override
public MetadataProviderResponse extractValue(ExtractValueRequest extractValueRequest, Property property) throws PersistenceException {
    if (!canHandleExtraction(extractValueRequest, property)) {
        return MetadataProviderResponse.NOT_HANDLED;
    }
    ObjectMapper mapper = new ObjectMapper();
    MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
    if (extractValueRequest.getMetadata().getFieldType() == SupportedFieldType.RULE_SIMPLE || extractValueRequest.getMetadata().getFieldType() == SupportedFieldType.RULE_SIMPLE_TIME) {
        extractSimpleRule(extractValueRequest, property, mapper, translator);
    }
    if (extractValueRequest.getMetadata().getFieldType() == SupportedFieldType.RULE_WITH_QUANTITY) {
        extractQuantityRule(extractValueRequest, mapper, translator);
    }
    return MetadataProviderResponse.HANDLED_BREAK;
}
Also used : MVELToDataWrapperTranslator(org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with MVELToDataWrapperTranslator

use of org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator 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 3 with MVELToDataWrapperTranslator

use of org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator 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 4 with MVELToDataWrapperTranslator

use of org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator 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 5 with MVELToDataWrapperTranslator

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

Aggregations

MVELToDataWrapperTranslator (org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator)13 Entity (org.broadleafcommerce.openadmin.dto.Entity)12 Property (org.broadleafcommerce.openadmin.dto.Property)12 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)12 ExpressionDTO (org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FieldData (org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldData)1