use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO in project BroadleafCommerce by BroadleafCommerce.
the class MVELToDataWrapperTranslator method postProcessCriteria.
protected void postProcessCriteria(DataDTO parentDTO, List<ExpressionDTO> myCriteriaList, ExpressionDTO temp, SupportedFieldType type) {
int lstIdx = myCriteriaList.size() - 1;
ExpressionDTO prevExpression = lstIdx != -1 ? myCriteriaList.get(lstIdx) : null;
boolean sameExpressionId = prevExpression != null && temp.getId().equals(prevExpression.getId());
if (sameExpressionId && isBetweenOperator(prevExpression, temp)) {
prevExpression.setOperator(BLCOperator.BETWEEN.name());
boolean hasTempSmallerVal = Long.parseLong(temp.getValue()) < Long.parseLong(prevExpression.getValue());
String start = hasTempSmallerVal ? temp.getValue() : prevExpression.getValue();
String end = hasTempSmallerVal ? prevExpression.getValue() : temp.getValue();
if (type.toString().equals(SupportedFieldType.DATE.toString())) {
start = "\"" + start + "\"";
end = "\"" + end + "\"";
}
prevExpression.setValue("[" + start + "," + end + "]");
if (parentDTO != null) {
parentDTO.getRules().add(myCriteriaList.remove(lstIdx));
}
} else if (sameExpressionId && isBetweenInclusiveOperator(prevExpression, temp)) {
prevExpression.setOperator(BLCOperator.BETWEEN_INCLUSIVE.name());
boolean hasTempSmallerVal = Long.parseLong(temp.getValue()) < Long.parseLong(prevExpression.getValue());
String start = hasTempSmallerVal ? temp.getValue() : prevExpression.getValue();
String end = hasTempSmallerVal ? prevExpression.getValue() : temp.getValue();
if (type.toString().equals(SupportedFieldType.DATE.toString())) {
start = "\"" + start + "\"";
end = "\"" + end + "\"";
}
prevExpression.setValue("[" + start + "," + end + "]");
if (parentDTO != null) {
parentDTO.getRules().add(myCriteriaList.remove(lstIdx));
}
} else if (isProjection(temp.getValue())) {
if (parentDTO != null) {
parentDTO.getRules().add(temp);
} else {
myCriteriaList.add(temp);
}
} else {
myCriteriaList.add(temp);
}
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO in project BroadleafCommerce by BroadleafCommerce.
the class MVELToDataWrapperTranslator method checkForInvalidSubGroup.
protected Boolean checkForInvalidSubGroup(DataDTO dataDTO) {
Boolean invalidSubGroupFound = false;
for (DataDTO rules : dataDTO.getRules()) {
ArrayList<DataDTO> subRules = rules.getRules();
if (subRules != null && subRules.size() == 2) {
ExpressionDTO expression1 = (ExpressionDTO) subRules.get(0);
ExpressionDTO expression2 = (ExpressionDTO) subRules.get(1);
Boolean isBetweenDetected = false;
Boolean isBetweenInclusiveDetected = false;
if (expression1.getOperator().equals("GREATER_THAN") && expression2.getOperator().equals("LESS_THAN")) {
isBetweenDetected = true;
}
if (expression1.getOperator().equals("GREATER_OR_EQUAL") && expression2.getOperator().equals("LESS_OR_EQUAL")) {
isBetweenInclusiveDetected = true;
}
if (!isBetweenDetected && !isBetweenInclusiveDetected) {
invalidSubGroupFound = true;
}
} else {
invalidSubGroupFound = true;
}
}
return invalidSubGroupFound;
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO in project BroadleafCommerce by BroadleafCommerce.
the class DataDTOToMVELTranslator method buildMVEL.
protected void buildMVEL(DataDTO dataDTO, StringBuffer sb, String entityKey, String groupOperator, RuleBuilderFieldService fieldService) throws MVELTranslationException {
BLCOperator operator = null;
if (dataDTO instanceof ExpressionDTO) {
operator = BLCOperator.valueOf(((ExpressionDTO) dataDTO).getOperator());
} else {
operator = BLCOperator.valueOf(dataDTO.getCondition());
}
ArrayList<DataDTO> groups = dataDTO.getRules();
if (sb.length() != 0 && sb.charAt(sb.length() - 1) != '(' && groupOperator != null) {
BLCOperator groupOp = BLCOperator.valueOf(groupOperator);
switch(groupOp) {
default:
sb.append("&&");
break;
case OR:
sb.append("||");
}
}
if (dataDTO instanceof ExpressionDTO) {
buildExpression((ExpressionDTO) dataDTO, sb, entityKey, operator, fieldService);
} else {
boolean includeTopLevelParenthesis = false;
if (sb.length() != 0 || BLCOperator.NOT.equals(operator) || (sb.length() == 0 && groupOperator != null)) {
includeTopLevelParenthesis = true;
}
if (BLCOperator.NOT.equals(operator)) {
sb.append("!");
}
if (includeTopLevelParenthesis)
sb.append("(");
for (DataDTO dto : groups) {
buildMVEL(dto, sb, entityKey, dataDTO.getCondition(), fieldService);
}
if (includeTopLevelParenthesis)
sb.append(")");
}
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO 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;
}
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO in project BroadleafCommerce by BroadleafCommerce.
the class MVELToDataWrapperTranslator method createExpressionDTO.
public ExpressionDTO createExpressionDTO(Expression expression) {
ExpressionDTO expressionDTO = new ExpressionDTO();
expressionDTO.setId(expression.getField());
expressionDTO.setOperator(expression.getOperator().name());
expressionDTO.setValue(expression.getValue());
return expressionDTO;
}
Aggregations