use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testRHSChangeMultipleFieldsBlockModify.
@Test
public void testRHSChangeMultipleFieldsBlockModify() {
String expected = "" + "rule \"my rule\" \n" + " dialect \"mvel\"\n" + " when\n" + " $p : Person()\n" + " then\n" + " modify( $p ) {\n" + " setName( \"Fred\" ),\n" + " setAge( 55 )\n" + " }\n" + " $p.setGender( \"X\" );" + "end\n";
final RuleModel m = new RuleModel();
FactPattern factPattern = new FactPattern();
factPattern.setFactType("Person");
factPattern.setBoundName("$p");
m.lhs = new IPattern[] { factPattern };
ActionUpdateField auf1 = new ActionUpdateField();
auf1.setVariable("$p");
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setField("name");
afv1.setType(DataType.TYPE_STRING);
afv1.setNature(FieldNatureType.TYPE_LITERAL);
afv1.setValue("Fred");
auf1.setFieldValues(new ActionFieldValue[] { afv1 });
ActionSetField asf = new ActionSetField();
asf.setVariable("$p");
ActionFieldValue afv2 = new ActionFieldValue();
afv2.setField("gender");
afv2.setType(DataType.TYPE_STRING);
afv2.setNature(FieldNatureType.TYPE_LITERAL);
afv2.setValue("X");
asf.setFieldValues(new ActionFieldValue[] { afv2 });
ActionUpdateField auf2 = new ActionUpdateField();
auf2.setVariable("$p");
ActionFieldValue afv3 = new ActionFieldValue();
afv3.setField("age");
afv3.setType(DataType.TYPE_NUMERIC_INTEGER);
afv3.setNature(FieldNatureType.TYPE_LITERAL);
afv3.setValue("55");
auf2.setFieldValues(new ActionFieldValue[] { afv3 });
m.rhs = new IAction[] { auf1, asf, auf2 };
m.name = "my rule";
checkMarshalling(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testRHSChangeMultipleFieldsModifyOneUpdateOther.
@Test
public void testRHSChangeMultipleFieldsModifyOneUpdateOther() {
String expected = "" + "rule \"my rule\" \n" + " dialect \"mvel\"\n" + " when\n" + " $p : Person()\n" + " then\n" + " modify( $p ) {\n" + " setName( \"Fred\" )\n" + " }\n" + " $p.setAge( 55 );\n" + "end\n";
final RuleModel m = new RuleModel();
FactPattern factPattern = new FactPattern();
factPattern.setFactType("Person");
factPattern.setBoundName("$p");
m.lhs = new IPattern[] { factPattern };
ActionUpdateField auf = new ActionUpdateField();
auf.setVariable("$p");
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setField("name");
afv1.setType(DataType.TYPE_STRING);
afv1.setNature(FieldNatureType.TYPE_LITERAL);
afv1.setValue("Fred");
auf.setFieldValues(new ActionFieldValue[] { afv1 });
ActionSetField asf = new ActionSetField();
asf.setVariable("$p");
ActionFieldValue afv2 = new ActionFieldValue();
afv2.setField("age");
afv2.setType(DataType.TYPE_NUMERIC_INTEGER);
afv2.setNature(FieldNatureType.TYPE_LITERAL);
afv2.setValue("55");
asf.setFieldValues(new ActionFieldValue[] { afv2 });
m.rhs = new IAction[] { auf, asf };
m.name = "my rule";
checkMarshalling(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testRHSChangeMultipleFieldsModifyBoth.
@Test
public void testRHSChangeMultipleFieldsModifyBoth() {
String expected = "" + "rule \"my rule\" \n" + " dialect \"mvel\"\n" + " when\n" + " $p : Person()\n" + " then\n" + " modify( $p ) {\n" + " setName( \"Fred\" ),\n" + " setAge( 55 )\n" + " }\n" + "end\n";
final RuleModel m = new RuleModel();
FactPattern factPattern = new FactPattern();
factPattern.setFactType("Person");
factPattern.setBoundName("$p");
m.lhs = new IPattern[] { factPattern };
ActionUpdateField auf = new ActionUpdateField();
auf.setVariable("$p");
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setField("name");
afv1.setType(DataType.TYPE_STRING);
afv1.setNature(FieldNatureType.TYPE_LITERAL);
afv1.setValue("Fred");
ActionFieldValue afv2 = new ActionFieldValue();
afv2.setField("age");
afv2.setType(DataType.TYPE_NUMERIC_INTEGER);
afv2.setNature(FieldNatureType.TYPE_LITERAL);
afv2.setValue("55");
auf.setFieldValues(new ActionFieldValue[] { afv1, afv2 });
m.rhs = new IAction[] { auf };
m.name = "my rule";
checkMarshalling(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method getComplexModel.
private RuleModel getComplexModel(boolean useDsl) {
final RuleModel m = new RuleModel();
m.name = "Complex Rule";
m.setPackageName("org.test");
m.addAttribute(new RuleAttribute("no-loop", "true"));
m.addAttribute(new RuleAttribute("salience", "-10"));
m.addAttribute(new RuleAttribute("agenda-group", "aGroup"));
final FactPattern pat = new FactPattern("Person");
pat.setBoundName("p1");
final SingleFieldConstraint con = new SingleFieldConstraint();
con.setFieldBinding("f1");
con.setFieldName("age");
con.setOperator("<");
con.setValue("42");
pat.addConstraint(con);
m.addLhsItem(pat);
final CompositeFactPattern comp = new CompositeFactPattern("not");
comp.addFactPattern(new FactPattern("Cancel"));
m.addLhsItem(comp);
final ActionUpdateField upd1 = new ActionUpdateField();
upd1.setVariable("p1");
upd1.addFieldValue(new ActionFieldValue("status", "rejected", DataType.TYPE_STRING));
upd1.addFieldValue(new ActionFieldValue("name", "Fred", DataType.TYPE_STRING));
m.addRhsItem(upd1);
final ActionRetractFact ret = new ActionRetractFact("p1");
m.addRhsItem(ret);
if (useDsl) {
final DSLSentence sen = new DSLSentence();
sen.setDefinition("Send an email to {administrator}");
m.addRhsItem(sen);
}
addModelField("org.test.Person", "this", "org.test.Person", DataType.TYPE_THIS);
addModelField("org.test.Person", "age", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
addModelField("org.test.Person", "status", String.class.getName(), DataType.TYPE_STRING);
return m;
}
use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools by kiegroup.
the class GuidedDTDRLPersistence method doAction.
private void doAction(List<LabelledAction> actions, ActionSetFieldCol52 sf, String cell) {
LabelledAction a = findByLabelledAction(actions, sf.getBoundName(), sf.isUpdate());
if (a == null) {
a = new LabelledAction();
a.boundName = sf.getBoundName();
a.isUpdate = sf.isUpdate();
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;
ActionFieldValue val = new ActionFieldValue(sf.getFactField(), cell, sf.getType());
asf.addFieldValue(val);
}
Aggregations