Search in sources :

Example 6 with ExpressionUnboundFact

use of org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testLHSExpressionNestedDate.

@Test
public void testLHSExpressionNestedDate() {
    RuleModel m = new RuleModel();
    m.name = "test expressionsNestedDate";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
    con.getExpressionLeftSide().appendPart(new ExpressionUnboundFact(p.getFactType()));
    con.getExpressionLeftSide().appendPart(new ExpressionField("favouriteCheese", "Cheese", DataType.TYPE_OBJECT));
    con.getExpressionLeftSide().appendPart(new ExpressionField("dateBrought", "java.util.Date", DataType.TYPE_DATE));
    con.setOperator("==");
    con.setValue("27-Jun-2011");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    String expected = "rule \"test expressionsNestedDate\"" + "\tdialect \"mvel\"\n when " + "     Person( favouriteCheese.dateBrought == \"27-Jun-2011\" )" + " then " + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Example 7 with ExpressionUnboundFact

use of org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testLHSExpressionNestedNumber.

@Test
public void testLHSExpressionNestedNumber() {
    RuleModel m = new RuleModel();
    m.name = "test expressionsNestedNumber";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
    con.getExpressionLeftSide().appendPart(new ExpressionUnboundFact(p.getFactType()));
    con.getExpressionLeftSide().appendPart(new ExpressionField("favouriteCheese", "Cheese", DataType.TYPE_OBJECT));
    con.getExpressionLeftSide().appendPart(new ExpressionField("age", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER));
    con.setOperator("==");
    con.setValue("55");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    String expected = "rule \"test expressionsNestedNumber\"" + "\tdialect \"mvel\"\n when " + "     Person( favouriteCheese.age == 55 )" + " then " + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Example 8 with ExpressionUnboundFact

use of org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testLHSExpressionNestedString.

@Test
public void testLHSExpressionNestedString() {
    RuleModel m = new RuleModel();
    m.name = "test expressionsNestedString";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
    con.getExpressionLeftSide().appendPart(new ExpressionUnboundFact(p.getFactType()));
    con.getExpressionLeftSide().appendPart(new ExpressionField("favouriteCheese", "Cheese", DataType.TYPE_OBJECT));
    con.getExpressionLeftSide().appendPart(new ExpressionField("name", "java.lang.String", DataType.TYPE_STRING));
    con.setOperator("==");
    con.setValue("Cheedar");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    String expected = "rule \"test expressionsNestedString\"" + "\tdialect \"mvel\"\n when " + "     Person( favouriteCheese.name == \"Cheedar\" )" + " then " + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Example 9 with ExpressionUnboundFact

use of org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact 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;
}
Also used : ExpressionMethodParameter(org.drools.workbench.models.datamodel.rule.ExpressionMethodParameter) ExpressionPart(org.drools.workbench.models.datamodel.rule.ExpressionPart) Label(com.google.gwt.user.client.ui.Label) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel) SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText) TextBox(org.gwtbootstrap3.client.ui.TextBox) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ExpressionTypeChangeEvent(org.drools.workbench.screens.guided.rule.client.editor.ExpressionTypeChangeEvent) ExpressionChangeEvent(org.drools.workbench.screens.guided.rule.client.editor.ExpressionChangeEvent) ExpressionChangeHandler(org.drools.workbench.screens.guided.rule.client.editor.ExpressionChangeHandler) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ExpressionTypeChangeHandler(org.drools.workbench.screens.guided.rule.client.editor.ExpressionTypeChangeHandler) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel)

Example 10 with ExpressionUnboundFact

use of org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testLHSExpressionDate.

@Test
public void testLHSExpressionDate() {
    RuleModel m = new RuleModel();
    m.name = "test expressionsDate";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
    con.getExpressionLeftSide().appendPart(new ExpressionUnboundFact(p.getFactType()));
    con.getExpressionLeftSide().appendPart(new ExpressionField("field1", "java.util.Date", DataType.TYPE_DATE));
    con.setOperator("==");
    con.setValue("27-Jun-2011");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    String expected = "rule \"test expressionsDate\"" + "\tdialect \"mvel\"\n when " + "     Person( field1 == \"27-Jun-2011\" )" + " then " + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Aggregations

ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)27 Test (org.junit.Test)25 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)24 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)24 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)24 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)24 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)24 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)24 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)24 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)21 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)12 ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)9 HashMap (java.util.HashMap)3 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)2 ExpressionCollection (org.drools.workbench.models.datamodel.rule.ExpressionCollection)2 ExpressionMethodParameter (org.drools.workbench.models.datamodel.rule.ExpressionMethodParameter)2 ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)2