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);
}
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();
}
});
}
}
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);
}
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);
}
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);
}
Aggregations