Search in sources :

Example 66 with FactPattern

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

the class RuleModelDRLPersistenceTest method testCompositeConstraintsRoundTrip.

@Test
public void testCompositeConstraintsRoundTrip() throws Exception {
    RuleModel m = new RuleModel();
    m.name = "with composite";
    FactPattern p1 = new FactPattern("Person");
    p1.setBoundName("p1");
    m.addLhsItem(p1);
    FactPattern p = new FactPattern("Goober");
    m.addLhsItem(p);
    CompositeFieldConstraint comp = new CompositeFieldConstraint();
    comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p.addConstraint(comp);
    final SingleFieldConstraint X = new SingleFieldConstraint();
    X.setFieldName("goo");
    X.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    X.setValue("foo");
    X.setOperator("==");
    X.setConnectives(new ConnectiveConstraint[1]);
    X.getConnectives()[0] = new ConnectiveConstraint();
    X.getConnectives()[0].setConstraintValueType(ConnectiveConstraint.TYPE_LITERAL);
    X.getConnectives()[0].setOperator("|| ==");
    X.getConnectives()[0].setValue("bar");
    comp.addConstraint(X);
    final SingleFieldConstraint Y = new SingleFieldConstraint();
    Y.setFieldName("goo2");
    Y.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    Y.setValue("foo");
    Y.setOperator("==");
    comp.addConstraint(Y);
    CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
    comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
    final SingleFieldConstraint Q1 = new SingleFieldConstraint();
    Q1.setFieldName("goo");
    Q1.setOperator("==");
    Q1.setValue("whee");
    Q1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    comp2.addConstraint(Q1);
    final SingleFieldConstraint Q2 = new SingleFieldConstraint();
    Q2.setFieldName("gabba");
    Q2.setOperator("==");
    Q2.setValue("whee");
    Q2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    comp2.addConstraint(Q2);
    // now nest it
    comp.addConstraint(comp2);
    final SingleFieldConstraint Z = new SingleFieldConstraint();
    Z.setFieldName("goo3");
    Z.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    Z.setValue("foo");
    Z.setOperator("==");
    p.addConstraint(Z);
    ActionInsertFact ass = new ActionInsertFact("Whee");
    m.addRhsItem(ass);
    String drl = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    PackageDataModelOracle dmo = mock(PackageDataModelOracle.class);
    RuleModel m2 = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.EMPTY_LIST, dmo);
    assertNotNull(m2);
    assertEquals("with composite", m2.name);
    assertEquals(m2.lhs.length, m.lhs.length);
    assertEquals(m2.rhs.length, m.rhs.length);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) 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) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 67 with FactPattern

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

the class RuleModelDRLPersistenceTest method testRHSExecuteWorkItem2.

@Test
public void testRHSExecuteWorkItem2() {
    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);
    p1.setBinding("");
    pwd.addParameter(p1);
    PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
    p2.setName("FloatParameter");
    p2.setValue(123.456f);
    p2.setBinding("");
    pwd.addParameter(p2);
    PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
    p3.setName("IntegerParameter");
    p3.setValue(123);
    p3.setBinding("");
    pwd.addParameter(p3);
    PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
    p4.setName("StringParameter");
    p4.setValue("hello");
    p4.setBinding("");
    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 68 with FactPattern

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

the class RuleModelDRLPersistenceTest method testLHSExpressionString2.

@Test
public void testLHSExpressionString2() {
    RuleModel m = new RuleModel();
    m.name = "test expressionsString2";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
    con.getExpressionLeftSide().appendPart(new ExpressionUnboundFact(p.getFactType()));
    con.getExpressionLeftSide().appendPart(new ExpressionField("field1", "java.lang.String", DataType.TYPE_STRING));
    con.setOperator("==");
    con.setValue("Cheddar");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    String expected = "rule \"test expressionsString2\"" + "\tdialect \"mvel\"\n when " + "     Person( field1 == \"Cheddar\" )" + " 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 69 with FactPattern

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

the class RuleModelDRLPersistenceTest method testLHSExpressionJavaEnum.

@Test
public void testLHSExpressionJavaEnum() {
    RuleModel m = new RuleModel();
    m.name = "test expressionsJavaEnum";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
    con.getExpressionLeftSide().appendPart(new ExpressionUnboundFact(p.getFactType()));
    con.getExpressionLeftSide().appendPart(new ExpressionField("field1", "CHEESE", DataType.TYPE_COMPARABLE));
    con.setOperator("==");
    con.setValue("CHEESE.Cheddar");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    String expected = "rule \"test expressionsJavaEnum\"" + "\tdialect \"mvel\"\n when " + "     Person( field1 == CHEESE.Cheddar )" + " 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 70 with FactPattern

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

the class RuleModelDRLPersistenceTest method testRHSSetMethodCallsMethodMVEL.

@Test
public void testRHSSetMethodCallsMethodMVEL() {
    String oldValue = System.getProperty("drools.dateformat");
    try {
        System.setProperty("drools.dateformat", "dd-MMM-yyyy");
        RuleModel m = new RuleModel();
        m.name = "RHS SetMethodCallsMethod";
        m.addAttribute(new RuleAttribute("dialect", "mvel"));
        FactPattern p = new FactPattern("Person");
        p.setBoundName("$p");
        m.addLhsItem(p);
        ActionCallMethod acm = new ActionCallMethod();
        acm.setMethodName("method");
        acm.setVariable("$p");
        acm.addFieldValue(new ActionFieldFunction("f1", "String", DataType.TYPE_STRING));
        acm.addFieldValue(new ActionFieldFunction("f2", "true", DataType.TYPE_BOOLEAN));
        acm.addFieldValue(new ActionFieldFunction("f3", "31-Jan-2012", DataType.TYPE_DATE));
        acm.addFieldValue(new ActionFieldFunction("f4", "100", DataType.TYPE_NUMERIC_INTEGER));
        acm.addFieldValue(new ActionFieldFunction("f5", "100", DataType.TYPE_NUMERIC_BIGDECIMAL));
        m.addRhsItem(acm);
        String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
        assertTrue(result.indexOf("java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");") != -1);
        assertTrue(result.indexOf("$p.method( \"String\", true, sdf.parse(\"31-Jan-2012\"), 100, 100B );") != -1);
        checkMarshalling(null, m);
    } finally {
        if (oldValue == null) {
            System.clearProperty("drools.dateformat");
        } else {
            System.setProperty("drools.dateformat", oldValue);
        }
    }
}
Also used : RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) 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) ActionFieldFunction(org.drools.workbench.models.datamodel.rule.ActionFieldFunction) 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