Search in sources :

Example 81 with FactPattern

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

the class RuleModelDRLPersistenceTest method testSumAsGivenValue.

@Test
public void testSumAsGivenValue() {
    // BZ-1013682
    String expected = "" + "rule \"my rule\" \n" + "  dialect \"mvel\"\n" + "  when\n" + "    m:Message()\n" + "  then\n" + "    modify( m ) {\n" + "      setText( \"Hello \" + \"world\" )\n" + "    }\n" + "end\n";
    final RuleModel m = new RuleModel();
    FactPattern factPattern = new FactPattern();
    factPattern.setFactType("Message");
    factPattern.setBoundName("m");
    m.lhs = new IPattern[] { factPattern };
    ActionUpdateField actionUpdateField = new ActionUpdateField();
    actionUpdateField.setVariable("m");
    ActionFieldValue actionFieldValue = new ActionFieldValue();
    actionFieldValue.setField("text");
    actionFieldValue.setType("String");
    actionFieldValue.setNature(FieldNatureType.TYPE_FORMULA);
    actionFieldValue.setValue("\"Hello \" + \"world\"");
    actionUpdateField.setFieldValues(new ActionFieldValue[] { actionFieldValue });
    m.rhs = new IAction[] { actionUpdateField };
    m.name = "my rule";
    checkMarshalling(expected, m);
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) 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 82 with FactPattern

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

the class RuleModelDRLPersistenceTest method testRHSExecuteWorkItem1.

@Test
public void testRHSExecuteWorkItem1() {
    RuleModel m = new RuleModel();
    m.name = "WorkItem";
    FactPattern p = new FactPattern("Person");
    p.setBoundName("$p");
    SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFieldType(DataType.TYPE_STRING);
    con.setFieldName("name");
    con.setOperator("==");
    con.setValue("Michael");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
    PortableWorkDefinition pwd = new PortableWorkDefinition();
    pwd.setName("WorkItem");
    awi.setWorkDefinition(pwd);
    PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
    p1.setName("BooleanParameter");
    p1.setValue(Boolean.TRUE);
    pwd.addParameter(p1);
    PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
    p2.setName("FloatParameter");
    p2.setValue(123.456f);
    pwd.addParameter(p2);
    PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
    p3.setName("IntegerParameter");
    p3.setValue(123);
    pwd.addParameter(p3);
    PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
    p4.setName("StringParameter");
    p4.setValue("hello");
    pwd.addParameter(p4);
    m.addRhsItem(awi);
    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("wiWorkItem.getParameters().put( \"BooleanParameter\", Boolean.TRUE );") != -1);
    assertTrue(result.indexOf("wiWorkItem.getParameters().put( \"FloatParameter\", 123.456f );") != -1);
    assertTrue(result.indexOf("wiWorkItem.getParameters().put( \"IntegerParameter\", 123 );") != -1);
    assertTrue(result.indexOf("wiWorkItem.getParameters().put( \"StringParameter\", \"hello\" );") != -1);
    assertTrue(result.indexOf("wim.internalExecuteWorkItem( wiWorkItem );") != -1);
    checkMarshalling(null, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) 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) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) ActionExecuteWorkItem(org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 83 with FactPattern

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

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

the class RuleModelDRLPersistenceTest method getCompositeFOL.

private RuleModel getCompositeFOL(String type) {
    RuleModel m = new RuleModel();
    m.name = "or";
    CompositeFactPattern cp = new CompositeFactPattern(type);
    FactPattern p1 = new FactPattern("Person");
    SingleFieldConstraint sf1 = new SingleFieldConstraint("age");
    sf1.setOperator("==");
    sf1.setValue("42");
    p1.addConstraint(sf1);
    cp.addFactPattern(p1);
    FactPattern p2 = new FactPattern("Person");
    SingleFieldConstraint sf2 = new SingleFieldConstraint("age");
    sf2.setOperator("==");
    sf2.setValue("43");
    p2.addConstraint(sf2);
    cp.addFactPattern(p2);
    m.addLhsItem(cp);
    return m;
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) 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) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel)

Example 85 with FactPattern

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

the class RuleModelDRLPersistenceTest method textIsNullOperator.

@Test
public void textIsNullOperator() {
    final RuleModel m = new RuleModel();
    m.name = "IsNullOperator";
    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)

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