Search in sources :

Example 46 with SingleFieldConstraint

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

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

use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint 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)

Example 49 with SingleFieldConstraint

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

the class RuleModelDRLPersistenceTest method testLiteralNoType.

@Test
public void testLiteralNoType() {
    RuleModel m = new RuleModel();
    m.name = "test literal no type";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFieldName("field1");
    con.setOperator("==");
    con.setValue("bananna");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    SingleFieldConstraint con2 = new SingleFieldConstraint();
    con2.setFieldName("field2");
    con2.setOperator("==");
    con2.setValue("variableHere");
    con2.setConstraintValueType(SingleFieldConstraint.TYPE_VARIABLE);
    p.addConstraint(con2);
    m.addLhsItem(p);
    String expected = "rule \"test literal no type\"" + "\tdialect \"mvel\"\n when " + "     Person(field1 == \"bananna\", field2 == variableHere)" + " then " + "end";
    checkMarshalling(expected, 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 50 with SingleFieldConstraint

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

the class RuleModelDRLPersistenceTest method testRHSDateInsertActionWithoutSystemProperty.

@Test
public void testRHSDateInsertActionWithoutSystemProperty() {
    // RHBRMS-3034
    String oldValue = System.getProperty("drools.dateformat");
    try {
        System.clearProperty("drools.dateformat");
        RuleModel m = new RuleModel();
        m.name = "RHS Date";
        FactPattern p = new FactPattern("Person");
        SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldType(DataType.TYPE_DATE);
        con.setFieldName("dateOfBirth");
        con.setOperator("==");
        con.setValue("31-Jan-2000");
        con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
        p.addConstraint(con);
        m.addLhsItem(p);
        ActionInsertFact ai = new ActionInsertFact("Birthday");
        ai.addFieldValue(new ActionFieldValue("dob", "31-Jan-2000", DataType.TYPE_DATE));
        m.addRhsItem(ai);
        String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
        assertTrue("result DRL : " + result, result.indexOf("java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");") != -1);
        assertTrue(result.indexOf("fact0.setDob( sdf.parse(\"31-Jan-2000\"") != -1);
        checkMarshalling(null, m);
    } finally {
        if (oldValue == null) {
            System.clearProperty("drools.dateformat");
        } else {
            System.setProperty("drools.dateformat", oldValue);
        }
    }
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) 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

SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)278 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)250 Test (org.junit.Test)242 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)236 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)218 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)199 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)148 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)142 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)138 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)73 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)65 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)64 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)62 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)28 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)27 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)25 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)23 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)21 ArrayList (java.util.ArrayList)20