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, 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.ActionUpdateField in project drools by kiegroup.
the class BRLRuleModelTest method testUpdateModifyMultipleFieldsWithMultipleSkipped4.
@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped4() {
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", "v1", 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" + " setF1( \"v1\" ),\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 testUpdateModifyMultipleFieldsWithMultipleSkipped2.
@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped2() {
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, "v2", "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" + " setF2( \"v2\" ),\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 testUpdateModifyMultipleFields.
@Test
public void testUpdateModifyMultipleFields() {
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("age", "$age", DataType.TYPE_NUMERIC_INTEGER));
auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction1.getDefinition().add(auf1);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Context", "age"));
dt.getActionCols().add(brlAction1);
BRLActionColumn brlAction2 = new BRLActionColumn();
ActionUpdateField auf2 = new ActionUpdateField("x");
auf2.addFieldValue(new ActionFieldValue("name", "$name", DataType.TYPE_STRING));
auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
brlAction2.getDefinition().add(auf2);
brlAction2.getChildColumns().add(new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Context", "name"));
dt.getActionCols().add(brlAction2);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", "55", "Fred" } }));
String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected1 = "//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" + " setAge( 55 ), \n" + " setName( \"Fred\" )\n" + "}\n" + "end\n";
assertEqualsIgnoreWhitespace(expected1, drl);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", "", "Fred" } }));
drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected2 = "//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" + " setName( \"Fred\" )\n" + "}\n" + "end\n";
assertEqualsIgnoreWhitespace(expected2, drl);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", "55", "" } }));
drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected3 = "//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" + " setAge( 55 ) \n" + "}\n" + "end\n";
assertEqualsIgnoreWhitespace(expected3, drl);
}
use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools by kiegroup.
the class BRLRuleModelTest method testUpdateModifyMultipleFieldsWithMultipleSkipped1.
@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped1() {
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", "v1", "v2", "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" + " setF1( \"v1\" ), \n" + " setF2( \"v2\" ),\n" + " setF3( \"v3\" )\n" + "}\n" + "end\n";
assertEqualsIgnoreWhitespace(expected, drl);
}
Aggregations