use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools by kiegroup.
the class BRLRuleModelTest method testDecisionTableColumnsWithRHS.
@Test
public void testDecisionTableColumnsWithRHS() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
Pattern52 p1 = new Pattern52();
p1.setFactType("Driver");
p1.setBoundName("$p1");
ConditionCol52 c1 = new ConditionCol52();
c1.setFactField("name");
c1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
c1.setBinding("$c1");
p1.getChildColumns().add(c1);
dt.getConditions().add(p1);
ActionInsertFactCol52 ins = new ActionInsertFactCol52();
ins.setBoundName("$ins");
ins.setFactField("rating");
ins.setFactType("Person");
ins.setType(DataType.TYPE_STRING);
dt.getActionCols().add(ins);
BRLActionColumn brlAction = new BRLActionColumn();
ActionInsertFact aif = new ActionInsertFact("Person");
aif.setBoundName("$aif");
aif.addFieldValue(new ActionFieldValue("rating", null, DataType.TYPE_STRING));
aif.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_LITERAL);
brlAction.getDefinition().add(aif);
dt.getActionCols().add(brlAction);
BRLRuleModel model = new BRLRuleModel(dt);
assertNotNull(model.getAllVariables());
assertEquals(4, model.getAllVariables().size());
assertTrue(model.getAllVariables().contains("$p1"));
assertTrue(model.getAllVariables().contains("$c1"));
assertTrue(model.getAllVariables().contains("$ins"));
assertTrue(model.getAllVariables().contains("$aif"));
assertNotNull(model.getRHSBoundFacts());
assertEquals(2, model.getRHSBoundFacts().size());
assertTrue(model.getRHSBoundFacts().contains("$ins"));
assertTrue(model.getRHSBoundFacts().contains("$aif"));
ActionInsertFact r1 = model.getRHSBoundFact("$ins");
assertNotNull(r1);
assertTrue(r1 instanceof ActionInsertFactCol52ActionInsertFactAdaptor);
ActionInsertFactCol52ActionInsertFactAdaptor raif1 = (ActionInsertFactCol52ActionInsertFactAdaptor) r1;
assertEquals("Person", raif1.getFactType());
assertEquals("rating", raif1.getFieldValues()[0].getField());
assertEquals(DataType.TYPE_STRING, raif1.getFieldValues()[0].getType());
assertNull(raif1.getFieldValues()[0].getValue());
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, raif1.getFieldValues()[0].getNature());
ActionInsertFact r2 = model.getRHSBoundFact("$aif");
assertNotNull(r2);
assertTrue(r2 instanceof ActionInsertFact);
ActionInsertFact raif2 = (ActionInsertFact) r2;
assertEquals("Person", raif2.getFactType());
assertEquals("rating", raif2.getFieldValues()[0].getField());
assertEquals(DataType.TYPE_STRING, raif2.getFieldValues()[0].getType());
assertNull(raif2.getFieldValues()[0].getValue());
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, raif2.getFieldValues()[0].getNature());
}
use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools-wb by kiegroup.
the class RuleModelCloneVisitor method visitActionFieldList.
// ActionInsertFact, ActionSetField, ActionpdateField
private ActionInsertFact visitActionFieldList(ActionInsertFact afl) {
ActionInsertFact clone = new ActionInsertFact();
clone.setFactType(afl.getFactType());
clone.setBoundName(afl.getBoundName());
for (ActionFieldValue afv : afl.getFieldValues()) {
ActionFieldValue afvClone = new ActionFieldValue();
afvClone.setField(afv.getField());
afvClone.setNature(afv.getNature());
afvClone.setType(afv.getType());
afvClone.setValue(afv.getValue());
clone.addFieldValue(afvClone);
}
return clone;
}
use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools-wb by kiegroup.
the class DefaultGuidedDecisionTableLinkManagerTest method fieldConstraintWithActionBRLFragmentFieldWithTemplateKey.
@Test
public void fieldConstraintWithActionBRLFragmentFieldWithTemplateKey() {
// Columns: Row#[0], Description[1], Action[2]
final GuidedDecisionTable52 dt1 = new GuidedDecisionTable52();
final BRLActionColumn brl = new BRLActionColumn();
final ActionInsertFact aif = new ActionInsertFact("Fact");
aif.addFieldValue(new ActionFieldValue() {
{
setField("field");
setValue("10");
setType(DataType.TYPE_STRING);
setNature(FieldNatureType.TYPE_TEMPLATE);
}
});
brl.setDefinition(new ArrayList<IAction>() {
{
add(aif);
}
});
brl.getChildColumns().add(new BRLActionVariableColumn("$f", DataType.TYPE_STRING, "Fact", "field"));
dt1.getActionCols().add(brl);
// Columns: Row#[0], Description[1], Condition[2]
final GuidedDecisionTable52 dt2 = new GuidedDecisionTable52();
final Pattern52 p2 = new Pattern52();
p2.setBoundName("$f");
p2.setFactType("Fact");
final ConditionCol52 p2c1 = new ConditionCol52();
p2c1.setFactField("field");
p2.getChildColumns().add(p2c1);
dt2.getConditions().add(p2);
manager.link(dt1, dt2, (s, t) -> {
assertEquals(2, s);
assertEquals(2, t);
});
}
use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools-wb by kiegroup.
the class GuidedDecisionTableFactory method makeTableWithBRLFragmentActionCol.
public static GuidedDecisionTable52 makeTableWithBRLFragmentActionCol(final String packageName, final Collection<Import> imports, final String tableName) {
final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setPackageName(packageName);
dt.getImports().getImports().addAll(imports);
dt.setTableName(tableName);
final BRLActionColumn brl = new BRLActionColumn();
final ActionInsertFact ifc1 = new ActionInsertFact();
ifc1.setFactType("Applicant");
ifc1.setBoundName("$a");
final ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("age");
afv1.setValue("f1");
ifc1.addFieldValue(afv1);
final ActionInsertFact ifc2 = new ActionInsertFact();
ifc2.setFactType("Mortgage");
ifc2.setBoundName("$m");
final ActionFieldValue afv2 = new ActionFieldValue();
afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
afv2.setField("amount");
afv2.setValue("f2");
ifc2.addFieldValue(afv2);
final ActionSetField asf = new ActionSetField();
asf.setVariable("$a");
asf.addFieldValue(new ActionFieldValue("age", "33", DataType.TYPE_NUMERIC_INTEGER));
final ActionUpdateField auf = new ActionUpdateField();
asf.setVariable("$m");
asf.addFieldValue(new ActionFieldValue("amount", "10000", DataType.TYPE_NUMERIC_INTEGER));
brl.getDefinition().add(ifc1);
brl.getDefinition().add(ifc2);
brl.getChildColumns().add(new BRLActionVariableColumn("f1", DataType.TYPE_NUMERIC_INTEGER));
brl.getChildColumns().add(new BRLActionVariableColumn("f2", DataType.TYPE_NUMERIC_INTEGER));
brl.getDefinition().add(asf);
brl.getDefinition().add(auf);
dt.getConditions().add(brl);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "33", "" } }));
return dt;
}
use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools-wb by kiegroup.
the class ActionValueEditor method getApplicableBindings.
private List<String> getApplicableBindings() {
List<String> bindings = new ArrayList<String>();
// Examine LHS Fact and Field bindings and RHS (new) Fact bindings
for (String v : modeller.getModel().getAllVariables()) {
// LHS FactPattern
FactPattern fp = modeller.getModel().getLHSBoundFact(v);
if (fp != null) {
if (isLHSFactTypeEquivalent(v)) {
bindings.add(v);
}
}
// LHS FieldConstraint
FieldConstraint fc = modeller.getModel().getLHSBoundField(v);
if (fc != null) {
if (isLHSFieldTypeEquivalent(v)) {
bindings.add(v);
}
}
// RHS ActionInsertFact
ActionInsertFact aif = modeller.getModel().getRHSBoundFact(v);
if (aif != null) {
if (isRHSFieldTypeEquivalent(v)) {
bindings.add(v);
}
}
}
return bindings;
}
Aggregations