use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSWithBRLColumn_ParseToDRL_MultiplePatterns.
@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into DRL
void testLHSWithBRLColumn_ParseToDRL_MultiplePatterns() {
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", "Pupa", "50" }, new String[] { "2", "desc", "", "50" }, new String[] { "3", "desc", "Pupa", "" } };
// 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);
FactPattern brl1DefinitionFactPattern2 = new FactPattern("Smurf");
SingleFieldConstraint brl1DefinitionFactPattern2Constraint1 = new SingleFieldConstraint();
brl1DefinitionFactPattern2Constraint1.setFieldType(DataType.TYPE_STRING);
brl1DefinitionFactPattern2Constraint1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
brl1DefinitionFactPattern2Constraint1.setFieldName("name");
brl1DefinitionFactPattern2Constraint1.setOperator("==");
brl1DefinitionFactPattern2Constraint1.setValue("$name");
brl1DefinitionFactPattern2.addConstraint(brl1DefinitionFactPattern2Constraint1);
SingleFieldConstraint brl1DefinitionFactPattern2Constraint2 = new SingleFieldConstraint();
brl1DefinitionFactPattern2Constraint2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
brl1DefinitionFactPattern2Constraint2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
brl1DefinitionFactPattern2Constraint2.setFieldName("age");
brl1DefinitionFactPattern2Constraint2.setOperator("==");
brl1DefinitionFactPattern2Constraint2.setValue("$age");
brl1DefinitionFactPattern2.addConstraint(brl1DefinitionFactPattern2Constraint2);
brl1Definition.add(brl1DefinitionFactPattern2);
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.BRLConditionColumn in project drools-wb by kiegroup.
the class ExtendedGuidedDecisionTableBuilder method createBRLConditionColumn.
public static BRLConditionColumn createBRLConditionColumn() {
final BRLConditionColumn brlConditionColumn = new BRLConditionColumn();
final ArrayList<IPattern> definition = new ArrayList<>();
definition.add(mock(IPattern.class));
brlConditionColumn.setDefinition(definition);
final ArrayList<BRLConditionVariableColumn> childColumns = new ArrayList<>();
final BRLConditionVariableColumn brlConditionVariableColumn = new BRLConditionVariableColumn();
brlConditionVariableColumn.getFactType();
childColumns.add(brlConditionVariableColumn);
brlConditionColumn.setChildColumns(childColumns);
return brlConditionColumn;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools-wb by kiegroup.
the class ExtendedGuidedDecisionTableBuilder method withConditionBRLColumn.
public ExtendedGuidedDecisionTableBuilder withConditionBRLColumn() {
final BRLConditionColumn column = createBRLConditionColumn();
table.getConditions().add(column);
return this;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools-wb by kiegroup.
the class DecisionTableAnalyzer method getColumnIndex.
private int getColumnIndex(final BaseColumn baseColumn) {
List<BaseColumn> cols = model.getExpandedColumns();
final int indexOf = cols.indexOf(baseColumn);
if (indexOf < 0) {
if (baseColumn instanceof BRLConditionColumn) {
for (final BaseColumn column : model.getExpandedColumns()) {
if (column instanceof BRLConditionVariableColumn) {
if (((BRLConditionColumn) baseColumn).getChildColumns().contains(column)) {
return model.getExpandedColumns().indexOf(column);
}
}
}
throw new IllegalArgumentException("Could not find BRLConditionColumn: " + baseColumn.toString());
}
if (baseColumn instanceof BRLActionColumn) {
for (final BaseColumn column : model.getExpandedColumns()) {
if (column instanceof BRLActionVariableColumn) {
if (((BRLActionColumn) baseColumn).getChildColumns().contains(column)) {
return model.getExpandedColumns().indexOf(column);
}
}
}
throw new IllegalArgumentException("Could not find BRLActionColumn: " + baseColumn.toString());
} else if (baseColumn instanceof BRLVariableColumn) {
return model.getExpandedColumns().indexOf(model.getBRLColumn((BRLVariableColumn) baseColumn));
} else {
throw new IllegalArgumentException("Could not find baseColumn: " + baseColumn.toString());
}
} else {
return indexOf;
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools-wb by kiegroup.
the class GuidedDecisionTableModelVisitor method getConsumedModelClasses.
public Set<String> getConsumedModelClasses() {
final Set<String> factTypes = new HashSet<String>();
// Extract Fact Types from model
for (CompositeColumn<?> cc : model.getConditions()) {
if (cc instanceof BRLConditionColumn) {
final List<IPattern> definition = ((BRLConditionColumn) cc).getDefinition();
factTypes.addAll(getConditionFactTypesFromRuleModel(definition));
} else if (cc instanceof Pattern52) {
factTypes.add(((Pattern52) cc).getFactType());
}
}
for (ActionCol52 c : model.getActionCols()) {
if (c instanceof BRLActionColumn) {
final List<IAction> definition = ((BRLActionColumn) c).getDefinition();
factTypes.addAll(getActionFactTypesFromRuleModel(definition));
} else if (c instanceof ActionInsertFactCol52) {
factTypes.add(((ActionInsertFactCol52) c).getFactType());
}
}
// Convert Fact Types into Fully Qualified Class Names
final Set<String> fullyQualifiedClassNames = new HashSet<String>();
for (String factType : factTypes) {
fullyQualifiedClassNames.add(convertToFullyQualifiedClassName(factType));
}
return fullyQualifiedClassNames;
}
Aggregations