use of org.broadleafcommerce.openadmin.web.rulebuilder.grouping.Group in project BroadleafCommerce by BroadleafCommerce.
the class MVELToDataWrapperTranslator method createRuleData.
public DataWrapper createRuleData(Entity[] entities, String mvelProperty, String quantityProperty, String idProperty, String containedProperty, RuleBuilderFieldService fieldService) {
if (entities == null || entities.length == 0 || mvelProperty == null) {
return null;
}
DataWrapper dataWrapper = new DataWrapper();
String mvel = null;
try {
for (Entity e : entities) {
Integer qty = null;
Long id = null;
Long containedId = null;
for (Property p : e.getProperties()) {
if (mvelProperty.equals(p.getName())) {
mvel = p.getValue();
}
if (quantityProperty != null && quantityProperty.equals(p.getName())) {
qty = Integer.parseInt(p.getValue());
}
if (idProperty != null && idProperty.equals(p.getName())) {
id = Long.parseLong(p.getValue());
}
if (containedProperty != null && containedProperty.equals(p.getName())) {
containedId = Long.parseLong(p.getValue());
}
}
if (mvel != null) {
Group group = groupingTranslator.createGroups(mvel);
DataDTO dataDTO = createRuleDataDTO(null, group, fieldService);
if (dataDTO != null) {
dataDTO.setPk(id);
dataDTO.setContainedPk(containedId);
dataDTO.setQuantity(qty);
dataWrapper.getData().add(dataDTO);
if (group.getSubGroups().size() > 0) {
Boolean invalidSubGroupFound = checkForInvalidSubGroup(dataDTO);
if (invalidSubGroupFound) {
throw new MVELTranslationException(MVELTranslationException.SUB_GROUP_DETECTED, SUB_GROUP_MESSAGE);
}
}
}
}
}
} catch (MVELTranslationException e) {
LOG.error("Unable to translate rule MVEL", e);
dataWrapper.getData().clear();
dataWrapper.setError(e.getLocalizedMessage());
dataWrapper.setRawMvel(mvel);
}
return dataWrapper;
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.grouping.Group in project BroadleafCommerce by BroadleafCommerce.
the class MVELToDataWrapperTranslator method createRuleDataDTO.
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.setCondition(operator.name());
List<ExpressionDTO> myCriteriaList = new ArrayList<ExpressionDTO>();
if (BLCOperator.NOT.equals(group.getOperatorType()) && group.getIsTopGroup()) {
group = group.getSubGroups().get(0);
group.setOperatorType(operator);
}
for (String phrase : group.getPhrases()) {
appendExpression(phrase, fieldService, parentDTO, myCriteriaList);
}
if (!myCriteriaList.isEmpty()) {
data.getRules().addAll(myCriteriaList);
}
for (Group subgroup : group.getSubGroups()) {
DataDTO subCriteria = createRuleDataDTO(data, subgroup, fieldService);
if (subCriteria != null && !subCriteria.getRules().isEmpty()) {
data.getRules().add(subCriteria);
}
}
if (data.getRules() != null && !data.getRules().isEmpty()) {
return data;
} else {
return null;
}
}
Aggregations