Search in sources :

Example 6 with BRLConditionColumn

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);
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ArrayList(java.util.ArrayList) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 7 with BRLConditionColumn

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;
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) ArrayList(java.util.ArrayList) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 8 with 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;
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)

Example 9 with BRLConditionColumn

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;
    }
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 10 with BRLConditionColumn

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;
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) IAction(org.drools.workbench.models.datamodel.rule.IAction) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) HashSet(java.util.HashSet)

Aggregations

BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)73 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)53 Test (org.junit.Test)49 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)30 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)26 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)26 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)24 ArrayList (java.util.ArrayList)22 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)22 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)22 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)21 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)17 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)16 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)15 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)14 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)14 IAction (org.drools.workbench.models.datamodel.rule.IAction)11 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 ExcelParser (org.drools.decisiontable.parser.xls.ExcelParser)10