Search in sources :

Example 71 with FactPattern

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

the class RuleModelDRLPersistenceTest method testCompositeFactPatternWithFrom.

@Test
public void testCompositeFactPatternWithFrom() {
    final RuleModel m = new RuleModel();
    m.name = "model";
    final FactPattern fp1 = new FactPattern("Data");
    fp1.setBoundName("$d");
    m.addLhsItem(fp1);
    final FactPattern fp2 = new FactPattern("Person");
    final FromCompositeFactPattern ffp1 = new FromCompositeFactPattern();
    ffp1.setExpression(new ExpressionFormLine(new ExpressionVariable(fp1.getBoundName(), fp1.getFactType())));
    ffp1.setFactPattern(fp2);
    m.addLhsItem(ffp1);
    final String actual = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    final String expected = "rule \"model\"\n" + "dialect \"mvel\"\n" + "when\n" + "$d : Data( )\n" + "(Person( ) from $d)\n" + "\n" + "then\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected, actual);
}
Also used : ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) 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) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 72 with FactPattern

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

the class RuleModelDRLPersistenceTest method testRHSActionWorkItemSetFields.

@Test
public // Test that WorkItem Parameters can be used to set fields on existing Facts
void testRHSActionWorkItemSetFields() {
    RuleModel m = new RuleModel();
    m.name = "WorkItem";
    FactPattern fp1 = new FactPattern("Results");
    fp1.setBoundName("$r");
    m.addLhsItem(fp1);
    ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
    PortableWorkDefinition pwd = new PortableWorkDefinition();
    pwd.setName("WorkItem");
    awi.setWorkDefinition(pwd);
    PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
    p1.setName("BooleanResult");
    pwd.addResult(p1);
    PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
    p2.setName("FloatResult");
    pwd.addResult(p2);
    PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
    p3.setName("IntegerResult");
    pwd.addResult(p3);
    PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
    p4.setName("StringResult");
    pwd.addResult(p4);
    m.addRhsItem(awi);
    ActionSetField asf = new ActionSetField();
    asf.setVariable("$r");
    ActionWorkItemFieldValue fv1 = new ActionWorkItemFieldValue("ResultsBooleanResult", DataType.TYPE_BOOLEAN, "WorkItem", "BooleanResult", Boolean.class.getName());
    asf.addFieldValue(fv1);
    ActionWorkItemFieldValue fv2 = new ActionWorkItemFieldValue("ResultsFloatResult", DataType.TYPE_NUMERIC_FLOAT, "WorkItem", "FloatResult", Float.class.getName());
    asf.addFieldValue(fv2);
    ActionWorkItemFieldValue fv3 = new ActionWorkItemFieldValue("ResultsIntegerResult", DataType.TYPE_NUMERIC_INTEGER, "WorkItem", "IntegerResult", Integer.class.getName());
    asf.addFieldValue(fv3);
    ActionWorkItemFieldValue fv4 = new ActionWorkItemFieldValue("ResultsStringResult", DataType.TYPE_STRING, "WorkItem", "StringResult", String.class.getName());
    asf.addFieldValue(fv4);
    m.addRhsItem(asf);
    String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertTrue(result.indexOf("org.drools.core.process.instance.WorkItemManager wim = (org.drools.core.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();") != -1);
    assertTrue(result.indexOf("org.drools.core.process.instance.impl.WorkItemImpl wiWorkItem = new org.drools.core.process.instance.impl.WorkItemImpl();") != -1);
    assertTrue(result.indexOf("$r.setResultsBooleanResult( (java.lang.Boolean) wiWorkItem.getResult( \"BooleanResult\" ) );") != -1);
    assertTrue(result.indexOf("$r.setResultsFloatResult( (java.lang.Float) wiWorkItem.getResult( \"FloatResult\" ) );") != -1);
    assertTrue(result.indexOf("$r.setResultsIntegerResult( (java.lang.Integer) wiWorkItem.getResult( \"IntegerResult\" ) );") != -1);
    assertTrue(result.indexOf("$r.setResultsStringResult( (java.lang.String) wiWorkItem.getResult( \"StringResult\" ) );") != -1);
    assertTrue(result.indexOf("wim.internalExecuteWorkItem( wiWorkItem );") != -1);
    checkMarshalling(null, m);
}
Also used : PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) 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) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) ActionExecuteWorkItem(org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem) Test(org.junit.Test)

Example 73 with FactPattern

use of org.drools.workbench.models.datamodel.rule.FactPattern 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 74 with FactPattern

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

the class RuleModelDRLPersistenceTest method textIsNotNullOperator.

@Test
public void textIsNotNullOperator() {
    final RuleModel m = new RuleModel();
    m.name = "IsNotNullOperator";
    final FactPattern pat = new FactPattern("Person");
    final SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFieldName("age");
    con.setOperator("!= null");
    pat.addConstraint(con);
    m.addLhsItem(pat);
    String s = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertTrue(s.indexOf("Person( age != null )") != -1);
    checkMarshalling(s, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) 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) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 75 with FactPattern

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

the class RuleModelDRLPersistenceTest method getModelWithNoConstraints.

private RuleModel getModelWithNoConstraints() {
    final RuleModel m = new RuleModel();
    m.name = "Complex Rule";
    final FactPattern pat = new FactPattern("Person");
    pat.setBoundName("p1");
    final SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFieldBinding("f1");
    con.setFieldName("age");
    // con.operator = "<";
    // con.value = "42";
    pat.addConstraint(con);
    m.addLhsItem(pat);
    return m;
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) 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) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel)

Aggregations

FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)399 Test (org.junit.Test)360 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)335 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)315 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)255 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)249 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)230 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)222 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)221 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)120 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)94 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)89 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)71 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)55 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)42 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)37 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)30 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)30 IAction (org.drools.workbench.models.datamodel.rule.IAction)28 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)24