use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper 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]"));
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper 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"));
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper in project BroadleafCommerce by BroadleafCommerce.
the class MVELToDataWrapperTranslatorTest method testBetweenDatesDataWrapper.
public void testBetweenDatesDataWrapper() throws MVELTranslationException {
MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
Property[] p1 = new Property[1];
Property m1 = new Property();
m1.setName("matchRule");
m1.setValue("(MvelHelper.convertField(\"DATE\",customer.?getCustomerAttributes()[\"invoice_date\"])>MvelHelper" + ".convertField(\"DATE\",\"2017.10.14 16:38:00 -0500\")&&MvelHelper.convertField(\"DATE\",customer" + ".?getCustomerAttributes()[\"invoice_date\"])<MvelHelper.convertField(\"DATE\"," + "\"2017.10.16 16:38:00 -0500\"))&&(MvelHelper.convertField(\"DATE\",customer.?getCustomerAttributes()" + "[\"invoice_date\"])>=MvelHelper.convertField(\"DATE\",\"2017.10.24 16:39:00 -0500\")&&MvelHelper" + ".convertField(\"DATE\",customer.?getCustomerAttributes()[\"invoice_date\"])<=MvelHelper" + ".convertField(\"DATE\",\"2017.10.25 16:40:00 -0500\"))");
Property q1 = new Property();
q1.setName("quantity");
q1.setValue("1");
Property i1 = new Property();
i1.setName("id");
i1.setValue("100");
p1[0] = m1;
Entity e1 = new Entity();
e1.setProperties(p1);
Entity[] entities = new Entity[1];
entities[0] = e1;
customerFieldService.getFields().add(new FieldData.Builder().label("Customer - invoice date").name("getCustomerAttributes()---invoice_date").operators(RuleOperatorType.DATE).options(RuleOptionType.EMPTY_COLLECTION).type(SupportedFieldType.DATE).build());
DataWrapper dataWrapper = translator.createRuleData(entities, "matchRule", null, null, customerFieldService);
customerFieldService.init();
assert (dataWrapper.getData().get(0).getRules().size() == 2);
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper in project BroadleafCommerce by BroadleafCommerce.
the class MVELToDataWrapperTranslatorTest method testItemQualificationDataWrapper.
public void testItemQualificationDataWrapper() 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("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() == 1);
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.EQUALS.name()));
assert (exp1.getValue().equals("test category"));
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\"]"));
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method buildMainListGrid.
@Override
public ListGrid buildMainListGrid(DynamicResultSet drs, ClassMetadata cmd, String sectionKey, List<SectionCrumb> sectionCrumbs) throws ServiceException {
List<Field> headerFields = new ArrayList<>();
ListGrid.Type type = ListGrid.Type.MAIN;
String idProperty = "id";
FieldWrapper wrapper = new FieldWrapper();
ArrayList<FieldDTO> defaultWrapperFields = new ArrayList<>();
for (Property p : cmd.getProperties()) {
if (p.getMetadata() instanceof BasicFieldMetadata) {
BasicFieldMetadata fmd = (BasicFieldMetadata) p.getMetadata();
if (SupportedFieldType.ID.equals(fmd.getFieldType())) {
idProperty = fmd.getName();
}
if (fmd.isProminent() != null && fmd.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), fmd.getVisibility())) {
Field hf = createHeaderField(p, fmd);
headerFields.add(hf);
defaultWrapperFields.add(constructFieldDTOFromFieldData(hf, fmd));
}
if (fmd.getIsFilter() != null && fmd.getIsFilter()) {
wrapper.getFields().add(constructFieldDTOFromFieldData(createHeaderField(p, fmd), fmd));
}
}
}
ListGrid listGrid = createListGrid(cmd.getCeilingType(), headerFields, type, drs, sectionKey, 0, idProperty, sectionCrumbs);
if (CollectionUtils.isNotEmpty(listGrid.getHeaderFields())) {
// Set the first column to be able to link to the main entity
listGrid.getHeaderFields().iterator().next().setMainEntityLink(true);
} else {
String message = "There are no listgrid header fields configured for the class " + cmd.getCeilingType();
message += "Please mark some @AdminPresentation fields with 'prominent = true'";
LOG.error(message);
}
Date c = new Date();
String friendlyName = "listGrid" + c.getTime();
// Set up the filter builder params
listGrid.setJsonFieldName(friendlyName + "Json");
listGrid.setFriendlyName(friendlyName);
listGrid.setFieldBuilder("RULE_SIMPLE");
if (CollectionUtils.isEmpty(wrapper.getFields())) {
wrapper.setFields(defaultWrapperFields);
}
listGrid.setFieldWrapper(wrapper);
listGrid.setHideFriendlyName(true);
String blankJsonString = "{\"data\":[]}";
listGrid.setJson(blankJsonString);
DataWrapper dw = convertJsonToDataWrapper(blankJsonString);
if (dw != null) {
listGrid.setDataWrapper(dw);
}
listGrid.addModalRowAction(DefaultListGridActions.SINGLE_SELECT);
listGrid.setSelectType(ListGrid.SelectType.SINGLE_SELECT);
extensionManager.getProxy().modifyListGrid(listGrid.getClassName(), listGrid);
return listGrid;
}
Aggregations