use of org.drools.workbench.models.datamodel.rule.ExpressionPart in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testSingleFieldConstraintEBLeftSide.
@Test
public void testSingleFieldConstraintEBLeftSide() throws Exception {
String drl = "" + "rule \" broken \"\n" + "dialect \"mvel\"\n" + " when\n" + " Customer( contact != null , contact.tel1 > \"15\" )\n" + " then\n" + "end";
addModelField("Customer", "contact", "Contact", "Contact");
addModelField("Contact", "tel1", "String", "String");
RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
FactPattern pattern = (FactPattern) m.lhs[0];
SingleFieldConstraint constraint = (SingleFieldConstraint) pattern.getFieldConstraints()[0];
assertEquals("Customer", constraint.getFactType());
assertEquals("contact", constraint.getFieldName());
assertEquals("Contact", constraint.getFieldType());
SingleFieldConstraintEBLeftSide constraint2 = (SingleFieldConstraintEBLeftSide) pattern.getFieldConstraints()[1];
assertEquals("tel1", constraint2.getFieldName());
assertEquals("String", constraint2.getFieldType());
assertEquals("15", constraint2.getValue());
assertEquals(">", constraint2.getOperator());
assertEquals(3, constraint2.getExpressionLeftSide().getParts().size());
ExpressionPart part1 = constraint2.getExpressionLeftSide().getParts().get(0);
assertEquals("Customer", part1.getName());
assertEquals("Customer", part1.getClassType());
assertEquals("Customer", part1.getGenericType());
ExpressionPart part2 = constraint2.getExpressionLeftSide().getParts().get(1);
assertEquals("contact", part2.getName());
assertEquals("Contact", part2.getClassType());
assertEquals("Contact", part2.getGenericType());
ExpressionPart part3 = constraint2.getExpressionLeftSide().getParts().get(2);
assertEquals("tel1", part3.getName());
assertEquals("String", part3.getClassType());
assertEquals("String", part3.getGenericType());
}
use of org.drools.workbench.models.datamodel.rule.ExpressionPart in project drools-wb by kiegroup.
the class ExpressionBuilder method createWidgetForExpression.
// Render Widgets for the Expression. ExpressionMethodParameter and ExpressionText parts
// are represented by a TextBox to allow the User to edit the values, Updates are
// reflected in the model.
private Widget createWidgetForExpression() {
final HorizontalPanel container = new HorizontalPanel();
container.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
container.setStylePrimaryName(GuidedRuleEditorResources.INSTANCE.css().container());
for (ExpressionPart expressionPart : expression.getParts()) {
if (expressionPart instanceof ExpressionUnboundFact) {
continue;
} else if (this.readOnly) {
container.add(new Label(expressionPart.getName()));
} else if (expressionPart instanceof ExpressionMethod) {
container.add(new Label(expressionPart.getName()));
container.add(new Label("("));
final ExpressionMethod em = (ExpressionMethod) expressionPart;
final List<ExpressionFormLine> emParams = em.getOrderedParams();
for (int index = 0; index < emParams.size(); index++) {
final ExpressionFormLine paramValueHolder = emParams.get(index);
final String paramDataType = em.getParameterDataType(paramValueHolder);
final ExpressionMethodParameter paramValue = ((ExpressionMethodParameter) paramValueHolder.getRootExpression());
final TextBox paramValueEditor = TextBoxFactory.getTextBox(paramDataType);
paramValueEditor.addValueChangeHandler(new ValueChangeHandler<String>() {
@Override
public void onValueChange(ValueChangeEvent<String> event) {
paramValue.setText(event.getValue());
}
});
paramValueEditor.setText(paramValue.getName());
container.add(paramValueEditor);
if (index < emParams.size() - 1) {
container.add(new Label(", "));
}
}
container.add(new Label(")"));
} else if (!(expressionPart instanceof ExpressionText)) {
container.add(new Label(expressionPart.getName()));
} else {
final TextBox tb = new TextBox();
final ExpressionText expressionTextPart = (ExpressionText) expressionPart;
tb.setText(expressionTextPart.getName());
tb.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(final ChangeEvent changeEvent) {
expressionTextPart.setText(tb.getText());
}
});
container.add(tb);
}
container.add(new Label("."));
}
return container;
}
use of org.drools.workbench.models.datamodel.rule.ExpressionPart in project drools-wb by kiegroup.
the class ExpressionBuilder method onStartPointChange.
private void onStartPointChange(final String value) {
setModified(true);
panel.clear();
final int dotPos = value.indexOf('.');
final String prefix = value.substring(0, dotPos);
final String attrib = value.substring(dotPos + 1);
if (prefix.equals(VARIABLE_VALUE_PREFIX)) {
FactPattern fact = getRuleModel().getLHSBoundFact(attrib);
ExpressionPart variable;
if (fact != null) {
variable = new ExpressionVariable(fact.getBoundName(), fact.getFactType());
} else {
// if the variable is not bound to a Fact Pattern then it must be bound to a Field
String lhsBindingType = getRuleModel().getLHSBindingType(attrib);
variable = new ExpressionFieldVariable(attrib, lhsBindingType);
}
expression.appendPart(variable);
onStartPointChangeUpdateWidget();
} else if (prefix.equals(GLOBAL_VARIABLE_VALUE_PREFIX)) {
ExpressionPartHelper.getExpressionPartForGlobalVariable(getDataModelOracle(), attrib, new Callback<ExpressionPart>() {
@Override
public void callback(final ExpressionPart part) {
expression.appendPart(part);
onStartPointChangeUpdateWidget();
}
});
}
}
Aggregations