use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools by kiegroup.
the class BRLRuleModelTest method testUpdateModifyMultipleFieldsWithMultipleSkipped3.
@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped3() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
Pattern52 p1 = new Pattern52();
p1.setBoundName("x");
p1.setFactType("Context");
ConditionCol52 c = new ConditionCol52();
c.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
p1.getChildColumns().add(c);
dt.getConditions().add(p1);
BRLActionColumn brlAction1 = new BRLActionColumn();
ActionUpdateField auf1 = new ActionUpdateField("x");
auf1.addFieldValue(new ActionFieldValue("f1", "$f1", DataType.TYPE_STRING));
auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction1.getDefinition().add(auf1);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f1", DataType.TYPE_STRING, "Context", "f1"));
ActionUpdateField auf2 = new ActionUpdateField("x");
auf2.addFieldValue(new ActionFieldValue("f2", "$f2", DataType.TYPE_STRING));
auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction1.getDefinition().add(auf2);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f2", DataType.TYPE_STRING, "Context", "f2"));
ActionUpdateField auf3 = new ActionUpdateField("x");
auf3.addFieldValue(new ActionFieldValue("f3", "$f3", DataType.TYPE_STRING));
auf3.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction1.getDefinition().add(auf3);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f3", DataType.TYPE_STRING, "Context", "f3"));
dt.getActionCols().add(brlAction1);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", null, null, "v3" } }));
String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + " x : Context( )\n" + "then\n" + " modify( x ) {\n" + " setF3( \"v3\" )\n" + "}\n" + "end\n";
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools by kiegroup.
the class BRLRuleModelTest method testRHSDelimitedNonEmptyStringValues.
@Test
public void testRHSDelimitedNonEmptyStringValues() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
dt.setTableName("extended-entry");
Pattern52 p1 = new Pattern52();
p1.setBoundName("p1");
p1.setFactType("Smurf");
BRLActionColumn brlAction = new BRLActionColumn();
ActionUpdateField auf1 = new ActionUpdateField("p1");
auf1.addFieldValue(new ActionFieldValue("name", "$name", DataType.TYPE_STRING));
auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
ActionUpdateField auf2 = new ActionUpdateField("p1");
auf2.addFieldValue(new ActionFieldValue("age", "$age", DataType.TYPE_NUMERIC_INTEGER));
auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction.getDefinition().add(auf1);
brlAction.getDefinition().add(auf2);
brlAction.getChildColumns().add(new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Smurf", "name"));
brlAction.getChildColumns().add(new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Smurf", "age"));
dt.getActionCols().add(brlAction);
// Test 1
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc-row1", null, null } }));
String drl1 = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected1 = "//from row number: 1\n" + "//desc-row1\n" + "rule \"Row 1 extended-entry\"\n" + " dialect \"mvel\"\n" + " when\n" + " then\n" + "end";
assertEqualsIgnoreWhitespace(expected1, drl1);
// Test 2
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 2l, "desc-row2", "\" \"", 35l } }));
String drl2 = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected2 = "//from row number: 1\n" + "//desc-row2\n" + "rule \"Row 2 extended-entry\"\n" + " dialect \"mvel\"\n" + " when\n" + " then\n" + " modify( p1 ) {\n" + " setName( \" \" ),\n" + " setAge( 35 )\n" + " }\n" + "end";
assertEqualsIgnoreWhitespace(expected2, drl2);
// Test 3
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 3l, "desc-row3", "\"\"", null } }));
String drl3 = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected3 = "//from row number: 1\n" + "//desc-row3\n" + "rule \"Row 3 extended-entry\"\n" + " dialect \"mvel\"\n" + " when\n" + " then\n" + " modify( p1 ) {\n" + " setName( \"\" )\n" + " }\n" + "end";
assertEqualsIgnoreWhitespace(expected3, drl3);
// Test 4
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 4l, "desc-row4", "\"\"", 35l } }));
String drl4 = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected4 = "//from row number: 1\n" + "//desc-row4\n" + "rule \"Row 4 extended-entry\"\n" + " dialect \"mvel\"\n" + " when\n" + " then\n" + " modify( p1 ) {\n" + " setName( \"\" ),\n" + " setAge( 35 )\n" + " }\n" + "end";
assertEqualsIgnoreWhitespace(expected4, drl4);
}
use of org.drools.workbench.models.datamodel.rule.ActionUpdateField 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.ActionUpdateField in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionModifyTwoFieldsFirstTemplateSecondTemplate3.
@Test
public void testActionModifyTwoFieldsFirstTemplateSecondTemplate3() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
fp.setBoundName("$p");
m.addLhsItem(fp);
ActionUpdateField auf1 = new ActionUpdateField("$p");
ActionFieldValue afv0 = new ActionFieldValue();
afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
afv0.setField("field1");
afv0.setValue("$f1");
auf1.addFieldValue(afv0);
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("field2");
afv1.setValue("$f2");
auf1.addFieldValue(afv1);
m.addRhsItem(auf1);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + " $p : Person()\n" + "then\n" + " modify( $p ) {\n" + " setField2(\"bar\")\n" + " }\n" + "end";
m.addRow(new String[] { null, "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionModifyTwoFieldsFirstLiteralSecondTemplate1.
@Test
public void testActionModifyTwoFieldsFirstLiteralSecondTemplate1() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
fp.setBoundName("$p");
m.addLhsItem(fp);
ActionUpdateField auf1 = new ActionUpdateField("$p");
ActionFieldValue afv0 = new ActionFieldValue();
afv0.setNature(FieldNatureType.TYPE_LITERAL);
afv0.setField("field1");
afv0.setValue("foo");
auf1.addFieldValue(afv0);
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("field2");
afv1.setValue("$f2");
auf1.addFieldValue(afv1);
m.addRhsItem(auf1);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + " $p : Person()\n" + "then\n" + " modify( $p ) {\n" + " setField1(\"foo\"),\n" + " setField2(\"bar\")\n" + " }\n" + "end";
m.addRow(new String[] { "bar" });
checkMarshall(expected, m);
}
Aggregations