use of org.drools.workbench.models.datamodel.rule.ActionSetField in project drools by kiegroup.
the class GuidedDTDRLPersistence method doAction.
private void doAction(List<LabelledAction> actions, ActionWorkItemSetFieldCol52 sf, String cell) {
if (Boolean.TRUE.equals(Boolean.parseBoolean(cell))) {
LabelledAction a = findByLabelledAction(actions, sf.getBoundName());
if (a == null) {
a = new LabelledAction();
a.boundName = sf.getBoundName();
if (!sf.isUpdate()) {
a.action = new ActionSetField(sf.getBoundName());
} else {
a.action = new ActionUpdateField(sf.getBoundName());
}
actions.add(a);
} else if (sf.isUpdate() && !(a.action instanceof ActionUpdateField)) {
// lets swap it out for an update as the user has asked for it.
ActionSetField old = (ActionSetField) a.action;
ActionUpdateField update = new ActionUpdateField(sf.getBoundName());
update.setFieldValues(old.getFieldValues());
a.action = update;
}
ActionSetField asf = (ActionSetField) a.action;
ActionWorkItemFieldValue val = new ActionWorkItemFieldValue(sf.getFactField(), sf.getType(), sf.getWorkItemName(), sf.getWorkItemResultParameterName(), sf.getParameterClassName());
asf.addFieldValue(val);
}
}
use of org.drools.workbench.models.datamodel.rule.ActionSetField in project drools by kiegroup.
the class BRLRuleModelTest method testRuleModelWithRHSBoundFactsUsageWithBRLActionColumn.
@Test
public void testRuleModelWithRHSBoundFactsUsageWithBRLActionColumn() {
final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
// Setup Decision Table columns
final Pattern52 p1 = new Pattern52();
p1.setFactType("Driver");
p1.setBoundName("$d");
dt.getConditions().add(p1);
final BRLActionColumn brl = new BRLActionColumn();
brl.setDefinition(Collections.singletonList(new ActionSetField() {
{
setVariable("$d");
}
}));
dt.getActionCols().add(brl);
final BRLRuleModel model = new BRLRuleModel(dt);
// Checks
assertTrue(model.isBoundFactUsed("$d"));
assertFalse(model.isBoundFactUsed("$cheese"));
}
use of org.drools.workbench.models.datamodel.rule.ActionSetField in project drools by kiegroup.
the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.
private List<Node> visit(final IAction a, final List<TypeNode> types, final GuidedDecisionTree model, final PackageDataModelOracle dmo, final List<ParserMessage> messages) {
final List<Node> nodes = new ArrayList<Node>();
if (a instanceof ActionRetractFact) {
final ActionRetractFact arf = (ActionRetractFact) a;
final String binding = arf.getVariableName();
for (TypeNode tn : types) {
if (tn.isBound()) {
if (tn.getBinding().equals(binding)) {
final ActionRetractNode arn = new ActionRetractNodeImpl(tn);
nodes.add(arn);
return nodes;
}
}
}
messages.add(new BindingNotFoundParserMessage(binding));
return nodes;
} else if (a instanceof ActionInsertLogicalFact) {
final ActionInsertLogicalFact aif = (ActionInsertLogicalFact) a;
final ActionInsertNode aun = new ActionInsertNodeImpl(aif.getFactType());
aun.setLogicalInsertion(true);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : aif.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(aif.getFactType(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
} else if (a instanceof ActionInsertFact) {
final ActionInsertFact aif = (ActionInsertFact) a;
final ActionInsertNode aun = new ActionInsertNodeImpl(aif.getFactType());
aun.setLogicalInsertion(false);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : aif.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(aif.getFactType(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
} else if (a instanceof ActionUpdateField) {
final ActionUpdateField auf = (ActionUpdateField) a;
final String binding = auf.getVariable();
for (TypeNode tn : types) {
if (tn.isBound()) {
if (tn.getBinding().equals(binding)) {
final ActionUpdateNode aun = new ActionUpdateNodeImpl(tn);
aun.setModify(true);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : auf.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(tn.getClassName(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
}
}
}
messages.add(new BindingNotFoundParserMessage(binding));
return nodes;
} else if (a instanceof ActionSetField) {
final ActionSetField asf = (ActionSetField) a;
final String binding = asf.getVariable();
for (TypeNode tn : types) {
if (tn.isBound()) {
if (tn.getBinding().equals(binding)) {
final ActionUpdateNode aun = new ActionUpdateNodeImpl(tn);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : asf.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(tn.getClassName(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
}
}
}
messages.add(new BindingNotFoundParserMessage(binding));
return nodes;
} else {
messages.add(new UnsupportedIActionParserMessage());
return nodes;
}
}
use of org.drools.workbench.models.datamodel.rule.ActionSetField in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionUpdateFactFirstValue.
@Test
public void testActionUpdateFactFirstValue() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
fp.setBoundName("$p");
m.addLhsItem(fp);
ActionSetField asf = new ActionSetField("$p");
ActionFieldValue afv0 = new ActionFieldValue();
afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
afv0.setField("field1");
afv0.setValue("$f1");
asf.addFieldValue(afv0);
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("field2");
afv1.setValue("$f2");
asf.addFieldValue(afv1);
m.addRhsItem(asf);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person()\n" + "then\n" + "$p.setField1(\"foo\");\n" + "end";
m.addRow(new String[] { "foo", null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionSetField in project drools-wb by kiegroup.
the class GuidedRuleTemplateFactory method makeModelWithActions.
public static TemplateModel makeModelWithActions(final String packageName, final Collection<Import> imports, final String name) {
final TemplateModel model = new TemplateModel();
model.getImports().getImports().addAll(imports);
model.setPackageName(packageName);
model.name = name;
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);
model.addRhsItem(ifc1);
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);
model.addRhsItem(ifc2);
final ActionSetField asf = new ActionSetField();
asf.setVariable("$a");
asf.addFieldValue(new ActionFieldValue("age", "33", DataType.TYPE_NUMERIC_INTEGER));
model.addRhsItem(asf);
final ActionUpdateField auf = new ActionUpdateField();
asf.setVariable("$m");
asf.addFieldValue(new ActionFieldValue("amount", "10000", DataType.TYPE_NUMERIC_INTEGER));
model.addRhsItem(auf);
model.addRow(new String[] { "33", null });
return model;
}
Aggregations