use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSWithBRLColumn_ParseToDRL_NoVariables.
@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into DRL
void testLHSWithBRLColumn_ParseToDRL_NoVariables() {
GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
// Row 0 should become an IPattern in the resulting RuleModel as it contains getValue()s for all Template fields in the BRL Column
// Row 1 should *NOT* become an IPattern in the resulting RuleModel as it does *NOT* contain getValue()s for all Template fields in the BRL Column
Object[][] data = new Object[][] { new Object[] { "1", "desc", Boolean.TRUE }, new Object[] { "2", "desc", Boolean.FALSE } };
// Simple (mandatory) columns
dtable.setRowNumberCol(new RowNumberCol52());
dtable.setDescriptionCol(new DescriptionCol52());
// BRL Column
BRLConditionColumn brl1 = new BRLConditionColumn();
// BRL Column definition
List<IPattern> brl1Definition = new ArrayList<IPattern>();
FactPattern brl1DefinitionFactPattern1 = new FactPattern("Baddie");
SingleFieldConstraint brl1DefinitionFactPattern1Constraint1 = new SingleFieldConstraint();
brl1DefinitionFactPattern1Constraint1.setFieldType(DataType.TYPE_STRING);
brl1DefinitionFactPattern1Constraint1.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
brl1DefinitionFactPattern1Constraint1.setFieldName("name");
brl1DefinitionFactPattern1Constraint1.setOperator("==");
brl1DefinitionFactPattern1Constraint1.setValue("Gargamel");
brl1DefinitionFactPattern1.addConstraint(brl1DefinitionFactPattern1Constraint1);
brl1Definition.add(brl1DefinitionFactPattern1);
brl1.setDefinition(brl1Definition);
// Setup BRL column bindings
BRLConditionVariableColumn brl1Variable1 = new BRLConditionVariableColumn("", DataType.TYPE_BOOLEAN);
brl1.getChildColumns().add(brl1Variable1);
dtable.getConditions().add(brl1);
dtable.setData(DataUtilities.makeDataLists(data));
// Now to test conversion
int ruleStartIndex;
int pattern1StartIndex;
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
String drl = p.marshal(dtable);
// Row 0
ruleStartIndex = drl.indexOf("//from row number: 1");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
assertFalse(pattern1StartIndex == -1);
// Row 1
ruleStartIndex = drl.indexOf("//from row number: 2");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
assertTrue(pattern1StartIndex == -1);
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools by kiegroup.
the class BRLRuleModelTest method testLHSNonEmptyStringValues.
@Test
public void testLHSNonEmptyStringValues() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
dt.setTableName("extended-entry");
BRLConditionColumn brlCondition = new BRLConditionColumn();
FactPattern fp = new FactPattern("Smurf");
fp.setBoundName("p1");
SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setOperator("==");
sfc1.setFactType("Smurf");
sfc1.setFieldName("name");
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setValue("$f1");
SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setOperator("==");
sfc2.setFactType("Smurf");
sfc2.setFieldName("age");
sfc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setValue("$f2");
fp.addConstraint(sfc1);
fp.addConstraint(sfc2);
brlCondition.getDefinition().add(fp);
brlCondition.getChildColumns().add(new BRLConditionVariableColumn("$f1", DataType.TYPE_STRING, "Smurf", "name"));
brlCondition.getChildColumns().add(new BRLConditionVariableColumn("$f2", DataType.TYPE_NUMERIC_INTEGER, "Smurf", "age"));
dt.getConditions().add(brlCondition);
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
// Test 1
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc-row1", "Pupa", null } }));
String drl1 = p.marshal(dt);
final String expected1 = "//from row number: 1\n" + "//desc-row1\n" + "rule \"Row 1 extended-entry\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf( name == \"Pupa\" )\n" + " then\n" + "end";
assertEqualsIgnoreWhitespace(expected1, drl1);
// Test 2
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 2l, "desc-row2", null, 35l } }));
String drl2 = p.marshal(dt);
final String expected2 = "//from row number: 1\n" + "//desc-row2\n" + "rule \"Row 2 extended-entry\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf( age == 35 )\n" + " then\n" + "end";
assertEqualsIgnoreWhitespace(expected2, drl2);
// Test 3
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 3l, "desc-row3", "Pupa", 35l } }));
String drl3 = p.marshal(dt);
final String expected3 = "//from row number: 1\n" + "//desc-row3\n" + "rule \"Row 3 extended-entry\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf( name == \"Pupa\", age == 35 )\n" + " then\n" + "end";
assertEqualsIgnoreWhitespace(expected3, drl3);
// Test 4
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 4l, "desc-row4", null, null } }));
String drl4 = p.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" + "end";
assertEqualsIgnoreWhitespace(expected4, drl4);
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools by kiegroup.
the class BRLRuleModelTest method testLHSDelimitedNonEmptyStringValues.
@Test
public void testLHSDelimitedNonEmptyStringValues() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
dt.setTableName("extended-entry");
BRLConditionColumn brlCondition = new BRLConditionColumn();
FactPattern fp = new FactPattern("Smurf");
fp.setBoundName("p1");
SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setOperator("==");
sfc1.setFactType("Smurf");
sfc1.setFieldName("name");
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setValue("$f1");
SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setOperator("==");
sfc2.setFactType("Smurf");
sfc2.setFieldName("age");
sfc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setValue("$f2");
fp.addConstraint(sfc1);
fp.addConstraint(sfc2);
brlCondition.getDefinition().add(fp);
brlCondition.getChildColumns().add(new BRLConditionVariableColumn("$f1", DataType.TYPE_STRING, "Smurf", "name"));
brlCondition.getChildColumns().add(new BRLConditionVariableColumn("$f2", DataType.TYPE_NUMERIC_INTEGER, "Smurf", "age"));
dt.getConditions().add(brlCondition);
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
// Test 1
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc-row1", null, null } }));
String drl1 = p.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 = p.marshal(dt);
final String expected2 = "//from row number: 1\n" + "//desc-row2\n" + "rule \"Row 2 extended-entry\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf( name == \" \", age == 35 )\n" + " then\n" + "end";
assertEqualsIgnoreWhitespace(expected2, drl2);
// Test 3
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 3l, "desc-row3", "\"\"", null } }));
String drl3 = p.marshal(dt);
final String expected3 = "//from row number: 1\n" + "//desc-row3\n" + "rule \"Row 3 extended-entry\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf( name == \"\" )\n" + " then\n" + "end";
assertEqualsIgnoreWhitespace(expected3, drl3);
// Test 4
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 4l, "desc-row4", "\"\"", 35l } }));
String drl4 = p.marshal(dt);
final String expected4 = "//from row number: 1\n" + "//desc-row4\n" + "rule \"Row 4 extended-entry\"\n" + " dialect \"mvel\"\n" + " when\n" + " p1 : Smurf( name == \"\", age == 35 )\n" + " then\n" + "end";
assertEqualsIgnoreWhitespace(expected4, drl4);
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSWithBRLColumn_ParseToDRL.
@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into DRL
void testLHSWithBRLColumn_ParseToDRL() {
GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
// All 3 rows should render, as the code is now lower down for skipping columns with empty cells
String[][] data = new String[][] { new String[] { "1", "desc", "Gargamel", "Pupa", "50" }, new String[] { "2", "desc", "Gargamel", "", "50" }, new String[] { "3", "desc", "Gargamel", "Pupa", "" } };
// Simple (mandatory) columns
dtable.setRowNumberCol(new RowNumberCol52());
dtable.setDescriptionCol(new DescriptionCol52());
// Simple Condition
Pattern52 p1 = new Pattern52();
p1.setFactType("Baddie");
ConditionCol52 con = new ConditionCol52();
con.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
con.setFactField("name");
con.setOperator("==");
p1.getChildColumns().add(con);
dtable.getConditions().add(p1);
// BRL Column
BRLConditionColumn brl1 = new BRLConditionColumn();
// BRL Column definition
List<IPattern> brl1Definition = new ArrayList<IPattern>();
FactPattern brl1DefinitionFactPattern1 = new FactPattern("Smurf");
SingleFieldConstraint brl1DefinitionFactPattern1Constraint1 = new SingleFieldConstraint();
brl1DefinitionFactPattern1Constraint1.setFieldType(DataType.TYPE_STRING);
brl1DefinitionFactPattern1Constraint1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
brl1DefinitionFactPattern1Constraint1.setFieldName("name");
brl1DefinitionFactPattern1Constraint1.setOperator("==");
brl1DefinitionFactPattern1Constraint1.setValue("$name");
brl1DefinitionFactPattern1.addConstraint(brl1DefinitionFactPattern1Constraint1);
SingleFieldConstraint brl1DefinitionFactPattern1Constraint2 = new SingleFieldConstraint();
brl1DefinitionFactPattern1Constraint2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
brl1DefinitionFactPattern1Constraint2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
brl1DefinitionFactPattern1Constraint2.setFieldName("age");
brl1DefinitionFactPattern1Constraint2.setOperator("==");
brl1DefinitionFactPattern1Constraint2.setValue("$age");
brl1DefinitionFactPattern1.addConstraint(brl1DefinitionFactPattern1Constraint2);
brl1Definition.add(brl1DefinitionFactPattern1);
brl1.setDefinition(brl1Definition);
// Setup BRL column bindings
BRLConditionVariableColumn brl1Variable1 = new BRLConditionVariableColumn("$name", DataType.TYPE_STRING, "Person", "name");
brl1.getChildColumns().add(brl1Variable1);
BRLConditionVariableColumn brl1Variable2 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Person", "age");
brl1.getChildColumns().add(brl1Variable2);
dtable.getConditions().add(brl1);
dtable.setData(DataUtilities.makeDataLists(data));
// Now to test conversion
int ruleStartIndex;
int pattern1StartIndex;
int pattern2StartIndex;
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
String drl = p.marshal(dtable);
System.out.println(drl);
// Row 0
ruleStartIndex = drl.indexOf("//from row number: 1");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
assertFalse(pattern1StartIndex == -1);
pattern2StartIndex = drl.indexOf("Smurf( name == \"Pupa\" , age == 50 )", ruleStartIndex);
assertFalse(pattern2StartIndex == -1);
// Row 1
ruleStartIndex = drl.indexOf("//from row number: 2");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
assertFalse(pattern1StartIndex == -1);
pattern2StartIndex = drl.indexOf("Smurf( age == 50 )", ruleStartIndex);
assertFalse(pattern2StartIndex == -1);
// Row 2
ruleStartIndex = drl.indexOf("//from row number: 3");
assertFalse(ruleStartIndex == -1);
pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
assertFalse(pattern1StartIndex == -1);
pattern2StartIndex = drl.indexOf("Smurf( name == \"Pupa\" )", ruleStartIndex);
assertFalse(pattern2StartIndex == -1);
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class DefaultGuidedDecisionTableLinkManager method link.
@Override
public void link(final GuidedDecisionTable52 model, final GuidedDecisionTable52 otherModel, final LinkFoundCallback callback) {
if (model == null) {
return;
}
if (otherModel == null) {
return;
}
if (callback == null) {
return;
}
final BRLRuleModel helper = new BRLRuleModel(model);
// Re-create links to other Decision Tables
for (CompositeColumn<? extends BaseColumn> otherDecisionTableConditions : otherModel.getConditions()) {
if (otherDecisionTableConditions instanceof Pattern52) {
final Pattern52 otherDecisionTablePattern = (Pattern52) otherDecisionTableConditions;
for (ConditionCol52 otherDecisionTableCondition : otherDecisionTablePattern.getChildColumns()) {
final String factType = otherDecisionTablePattern.getFactType();
final String fieldName = otherDecisionTableCondition.getFactField();
final ActionCol52 linkedActionColumn = getLinkedActionColumn(factType, fieldName, model, helper);
if (linkedActionColumn != null) {
final int sourceColumnIndex = model.getExpandedColumns().indexOf(linkedActionColumn);
final int targetColumnIndex = otherModel.getExpandedColumns().indexOf(otherDecisionTableCondition);
callback.link(sourceColumnIndex, targetColumnIndex);
}
}
} else if (otherDecisionTableConditions instanceof BRLConditionColumn) {
final BRLConditionColumn fragment = (BRLConditionColumn) otherDecisionTableConditions;
for (BRLConditionVariableColumn var : fragment.getChildColumns()) {
final String factType = var.getFactType();
final String fieldName = var.getFactField();
final ActionCol52 linkedActionColumn = getLinkedActionColumn(factType, fieldName, model, helper);
if (linkedActionColumn != null) {
final int sourceColumnIndex = model.getExpandedColumns().indexOf(linkedActionColumn);
final int targetColumnIndex = otherModel.getExpandedColumns().indexOf(var);
callback.link(sourceColumnIndex, targetColumnIndex);
}
}
}
}
}
Aggregations