Package org.broadleafcommerce.openadmin.web.rulebuilder.dto

Examples of org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO


    protected String convertMatchRuleJsonToMvel(DataDTOToMVELTranslator translator, String entityKey,
                                                      String fieldService, DataWrapper dw) {
        String mvel = null;
        //there can only be one DataDTO for an appliesTo* rule
        if (dw != null && dw.getData().size() == 1) {
            DataDTO dto = dw.getData().get(0);
            try {
                mvel = translator.createMVEL(entityKey, dto,
                        ruleBuilderFieldServiceFactory.createInstance(fieldService));
            } catch (MVELTranslationException e) {
                throw new RuntimeException(e);
View Full Code Here


                    }
                }

                if (mvel != null) {
                    Group group = groupingTranslator.createGroups(mvel);
                    DataDTO dataDTO = createRuleDataDTO(null, group, fieldService);
                    if (dataDTO != null) {
                        dataDTO.setId(id);
                        dataDTO.setQuantity(qty);
                        dataWrapper.getData().add(dataDTO);
                    }
                }
            }
        } catch (MVELTranslationException e) {
View Full Code Here

        return dataWrapper;
    }

    protected DataDTO createRuleDataDTO(DataDTO parentDTO, Group group, RuleBuilderFieldService fieldService)
        throws MVELTranslationException {
        DataDTO data = new DataDTO();
        if (group.getOperatorType() == null) {
            group.setOperatorType(BLCOperator.AND);
        }
        BLCOperator operator = group.getOperatorType();
        data.setGroupOperator(operator.name());
        List<ExpressionDTO> myCriteriaList = new ArrayList<ExpressionDTO>();
        if (BLCOperator.NOT.equals(group.getOperatorType()) && group.getIsTopGroup()) {
            group = group.getSubGroups().get(0);
            group.setOperatorType(operator);
        }
        int j = 0;
        for (String phrase : group.getPhrases()) {
            appendExpression(phrase, fieldService, j, parentDTO, myCriteriaList);
            j++;
        }
        if (myCriteriaList.size() > 0) {
            data.getGroups().addAll(myCriteriaList);
        }
        for (Group subgroup : group.getSubGroups()) {
            DataDTO subCriteria = createRuleDataDTO(data, subgroup, fieldService);
            if (subCriteria != null && !subCriteria.getGroups().isEmpty()) {
                data.getGroups().add(subCriteria);
            }
        }
        if (data.getGroups() != null && !data.getGroups().isEmpty()) {
            return data;
View Full Code Here

    public DataDTO deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        ObjectMapper mapper = (ObjectMapper) jp.getCodec();
        ObjectNode root = (ObjectNode) mapper.readTree(jp);
        Iterator<Map.Entry<String, JsonNode>> elementsIterator =
                root.getFields();
        DataDTO dataDTO = new DataDTO();
        ExpressionDTO expressionDTO = new ExpressionDTO();
        boolean isExpression = false;
        while (elementsIterator.hasNext()) {
            Map.Entry<String, JsonNode> element=elementsIterator.next();
            String name = element.getKey();
            if ("name".equals(name)) {
                expressionDTO.setName(element.getValue().asText());
                isExpression = true;
            }
            if ("operator".equals(name)) {
                expressionDTO.setOperator(element.getValue().asText());
                isExpression = true;
            }
            if ("value".equals(name)) {
                expressionDTO.setValue(element.getValue().asText());
                isExpression = true;
            }
            if ("start".equals(name)) {
                expressionDTO.setStart(element.getValue().asText());
                isExpression = true;
            }
            if ("end".equals(name)) {
                expressionDTO.setEnd(element.getValue().asText());
                isExpression = true;
            }
            if ("id".equals(name)) {
                if ("null".equals(element.getValue().asText())) {
                    dataDTO.setId(null);
                } else {
                    dataDTO.setId(element.getValue().asLong());
                }
            }
            if ("quantity".equals(name)) {
                if ("null".equals(element.getValue().asText())) {
                    dataDTO.setQuantity(null);
                } else {
                    dataDTO.setQuantity(element.getValue().asInt());
                }
            }
            if ("groupOperator".equals(name)) {
                dataDTO.setGroupOperator(element.getValue().asText());
            }
            if ("groups".equals(name)){
                dataDTO.setGroups((ArrayList<DataDTO>)mapper.readValue(element.getValue(), new TypeReference<ArrayList<DataDTO>>(){}));
            }


        }
View Full Code Here

     *      "value":"true"}]
     }]
     */
    public void testCustomerQualificationMVEL() throws MVELTranslationException {
        DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator();
        DataDTO dataDTO = new DataDTO();
        dataDTO.setGroupOperator(BLCOperator.AND.name());

        //not currently supported
//        ExpressionDTO e1 = new ExpressionDTO();
//        e1.setName("emailAddress");
//        e1.setOperator(BLCOperator.NOT_EQUAL_FIELD.name());
//        e1.setValue("username");

        ExpressionDTO e2 = new ExpressionDTO();
        e2.setName("deactivated");
        e2.setOperator(BLCOperator.EQUALS.name());
        e2.setValue("true");

        //dataDTO.getGroups().add(e1);
        dataDTO.getGroups().add(e2);

        String translated = translator.createMVEL("customer", dataDTO, customerFieldService);
        String mvel = "customer.?deactivated==true";
        assert (mvel.equals(translated));
    }
View Full Code Here

     *      }]
     }]
     */
    public void testOrderQualificationMVEL() throws MVELTranslationException {
        DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator();
        DataDTO dataDTO = new DataDTO();
        dataDTO.setGroupOperator(BLCOperator.AND.name());

        ExpressionDTO expressionDTO = new ExpressionDTO();
        expressionDTO.setName("subTotal");
        expressionDTO.setOperator(BLCOperator.GREATER_OR_EQUAL.name());
        expressionDTO.setValue("100");
        dataDTO.getGroups().add(expressionDTO);

        DataDTO d1 = new DataDTO();
        d1.setGroupOperator(BLCOperator.OR.name());

        ExpressionDTO e1 = new ExpressionDTO();
        e1.setName("currency.defaultFlag");
        e1.setOperator(BLCOperator.EQUALS.name());
        e1.setValue("true");

        ExpressionDTO e2 = new ExpressionDTO();
        e2.setName("locale.localeCode");
        e2.setOperator(BLCOperator.EQUALS.name());
        e2.setValue("my");

        d1.getGroups().add(e1);
        d1.getGroups().add(e2);

        dataDTO.getGroups().add(d1);

        String translated = translator.createMVEL("order", dataDTO, orderFieldService);
        String mvel = "order.?subTotal.getAmount()>=100&&(order.?currency.?defaultFlag==true||order.?locale.?localeCode==\"my\")";
View Full Code Here

     }]
     */
    public void testItemQualificationMVEL() throws MVELTranslationException {
        DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator();

        DataDTO d1 = new DataDTO();
        d1.setQuantity(1);
        d1.setGroupOperator(BLCOperator.AND.name());
        ExpressionDTO d1e1 = new ExpressionDTO();
        d1e1.setName("category.name");
        d1e1.setOperator(BLCOperator.EQUALS.name());
        d1e1.setValue("test category");
        d1.getGroups().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(2);
        d2.setGroupOperator(BLCOperator.NOT.name());
        ExpressionDTO d2e1 = new ExpressionDTO();
        d2e1.setName("product.manufacturer");
        d2e1.setOperator(BLCOperator.EQUALS.name());
        d2e1.setValue("test manufacturer");
        ExpressionDTO d2e2 = new ExpressionDTO();
        d2e2.setName("product.model");
        d2e2.setOperator(BLCOperator.EQUALS.name());
        d2e2.setValue("test model");
        d2.getGroups().add(d2e1);
        d2.getGroups().add(d2e2);

        String d2Translated = translator.createMVEL("discreteOrderItem", d2, orderItemFieldService);
        String d2Mvel = "!(discreteOrderItem.?product.?manufacturer==\"test manufacturer\"&&discreteOrderItem.?product.?model==\"test model\")";
        assert (d2Mvel.equals(d2Translated));

View Full Code Here

     *      "end":"199"}]
     }]
     */
    public void testFulfillmentQualificationMVEL() throws MVELTranslationException {
        DataDTOToMVELTranslator translator = new DataDTOToMVELTranslator();
        DataDTO dataDTO = new DataDTO();
        dataDTO.setGroupOperator(BLCOperator.AND.name());

        ExpressionDTO e1 = new ExpressionDTO();
        e1.setName("address.state.name");
        e1.setOperator(BLCOperator.EQUALS.name());
        e1.setValue("Texas");

        ExpressionDTO e2 = new ExpressionDTO();
        e2.setName("retailFulfillmentPrice");
        e2.setOperator(BLCOperator.BETWEEN_INCLUSIVE.name());
        e2.setStart("99");
        e2.setEnd("199");

        dataDTO.getGroups().add(e1);
        dataDTO.getGroups().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));
    }
View Full Code Here

        assert(e1.getName().equals("subTotal"));
        assert(e1.getOperator().equals(BLCOperator.GREATER_OR_EQUAL.name()));
        assert(e1.getValue().equals("100"));

        assert(dataWrapper.getData().get(0).getGroups().get(1) != null);
        DataDTO d1 = dataWrapper.getData().get(0).getGroups().get(1);
        assert(d1.getGroupOperator().equals(BLCOperator.OR.name()));
        assert(d1.getGroups().get(0) instanceof ExpressionDTO);
        ExpressionDTO d1e1 = (ExpressionDTO) d1.getGroups().get(0);
        assert(d1e1.getName().equals("currency.defaultFlag"));
        assert(d1e1.getOperator().equals(BLCOperator.EQUALS.name()));
        assert(d1e1.getValue().equals("true"));
        assert(d1.getGroups().get(1) instanceof ExpressionDTO);
        ExpressionDTO d1e2 = (ExpressionDTO) d1.getGroups().get(1);
        assert(d1e2.getName().equals("locale.localeCode"));
        assert(d1e2.getOperator().equals(BLCOperator.EQUALS.name()));
        assert(d1e2.getValue().equals("my"));

    }
View Full Code Here

TOP

Related Classes of org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.