Search in sources :

Example 36 with ActionInsertFact

use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools-wb by kiegroup.

the class BRLActionColumnDefinitionBuilderTest method setupBRLActionColumn.

private void setupBRLActionColumn() {
    final BRLActionColumn brl = new BRLActionColumn();
    final ActionInsertFact ifc1 = new ActionInsertFact();
    ifc1.setFactType("Person");
    ifc1.setBoundName("$a");
    final ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("name");
    afv1.setValue("f1");
    ifc1.addFieldValue(afv1);
    final ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv2.setField("age");
    afv2.setValue("f2");
    ifc1.addFieldValue(afv2);
    brl.getDefinition().add(ifc1);
    brl.getChildColumns().add(new BRLActionVariableColumn("f1", DataType.TYPE_STRING));
    brl.getChildColumns().add(new BRLActionVariableColumn("f2", DataType.TYPE_NUMERIC_INTEGER));
    model.getActionCols().add(brl);
    when(dmo.getFieldType(eq("Person"), eq("name"))).thenReturn(DataType.TYPE_STRING);
    when(dmo.getFieldType(eq("Person"), eq("age"))).thenReturn(DataType.TYPE_NUMERIC_INTEGER);
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)

Example 37 with ActionInsertFact

use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools-wb by kiegroup.

the class RuleModellerActionSelectorPopup method addInsertions.

// Add insertions
void addInsertions() {
    if (oracle.getFactTypes().length == 0) {
        return;
    }
    choices.addItem(SECTION_SEPARATOR);
    for (int i = 0; i < oracle.getFactTypes().length; i++) {
        final String item = oracle.getFactTypes()[i];
        choices.addItem(GuidedRuleEditorResources.CONSTANTS.InsertFact0(item), "INS" + item);
        cmds.put("INS" + item, new Command() {

            public void execute() {
                model.addRhsItem(new ActionInsertFact(item), Integer.parseInt(positionCbo.getValue(positionCbo.getSelectedIndex())));
                hide();
            }
        });
    }
}
Also used : Command(com.google.gwt.user.client.Command) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact)

Example 38 with ActionInsertFact

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

the class RuleTemplateModelDRLPersistenceTest method testActionInsertFactFirstValue.

@Test
public void testActionInsertFactFirstValue() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FactPattern fp = new FactPattern("Person");
    fp.setBoundName("$p");
    m.addLhsItem(fp);
    ActionInsertFact aif = new ActionInsertFact("Present");
    aif.setBoundName("f0");
    ActionFieldValue afv0 = new ActionFieldValue();
    afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv0.setField("field1");
    afv0.setValue("$f1");
    aif.addFieldValue(afv0);
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("field2");
    afv1.setValue("$f2");
    aif.addFieldValue(afv1);
    m.addRhsItem(aif);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person()\n" + "then\n" + "Present f0 = new Present();\n" + "f0.setField1(\"foo\");\n" + "insert(f0);\n" + "end";
    m.addRow(new String[] { "foo", null });
    checkMarshall(expected, m);
}
Also used : ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 39 with ActionInsertFact

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

the class RuleTemplateModelDRLPersistenceTest method testActionInsertFactBothValues.

@Test
public void testActionInsertFactBothValues() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FactPattern fp = new FactPattern("Person");
    fp.setBoundName("$p");
    m.addLhsItem(fp);
    ActionInsertFact aif = new ActionInsertFact("Present");
    aif.setBoundName("f0");
    ActionFieldValue afv0 = new ActionFieldValue();
    afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv0.setField("field1");
    afv0.setValue("$f1");
    aif.addFieldValue(afv0);
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("field2");
    afv1.setValue("$f2");
    aif.addFieldValue(afv1);
    m.addRhsItem(aif);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person()\n" + "then\n" + "Present f0 = new Present();\n" + "f0.setField1(\"foo\");\n" + "f0.setField2(\"bar\");\n" + "insert(f0);\n" + "end";
    m.addRow(new String[] { "foo", "bar" });
    checkMarshall(expected, m);
}
Also used : ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 40 with ActionInsertFact

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

the class RuleTemplateModelDRLPersistenceTest method testActionInsertFactSecondValue.

@Test
public void testActionInsertFactSecondValue() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FactPattern fp = new FactPattern("Person");
    fp.setBoundName("$p");
    m.addLhsItem(fp);
    ActionInsertFact aif = new ActionInsertFact("Present");
    aif.setBoundName("f0");
    ActionFieldValue afv0 = new ActionFieldValue();
    afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv0.setField("field1");
    afv0.setValue("$f1");
    aif.addFieldValue(afv0);
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("field2");
    afv1.setValue("$f2");
    aif.addFieldValue(afv1);
    m.addRhsItem(aif);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person()\n" + "then\n" + "Present f0 = new Present();\n" + "f0.setField2(\"bar\");\n" + "insert(f0);\n" + "end";
    m.addRow(new String[] { null, "bar" });
    checkMarshall(expected, m);
}
Also used : ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Aggregations

ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)78 Test (org.junit.Test)64 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)48 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)47 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)43 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)42 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)39 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)34 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)34 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)34 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)32 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)24 IAction (org.drools.workbench.models.datamodel.rule.IAction)17 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)13 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)12 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)12 ArrayList (java.util.ArrayList)11 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)10 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)10 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)10