Search in sources :

Example 11 with BRLActionVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.

the class DefaultGuidedDecisionTableLinkManagerTest method fieldConstraintWithActionBRLFragmentFieldWithoutTemplateKey.

@Test
public void fieldConstraintWithActionBRLFragmentFieldWithoutTemplateKey() {
    // Columns: Row#[0], Description[1], Action[2]
    final GuidedDecisionTable52 dt1 = new GuidedDecisionTable52();
    final BRLActionColumn brl = new BRLActionColumn();
    final ActionInsertFact aif = new ActionInsertFact();
    aif.setFactType("Fact");
    aif.addFieldValue(new ActionFieldValue() {

        {
            setField("field");
            setValue("10");
            setNature(FieldNatureType.TYPE_LITERAL);
        }
    });
    brl.setDefinition(new ArrayList<IAction>() {

        {
            add(aif);
        }
    });
    brl.getChildColumns().add(new BRLActionVariableColumn("", DataType.TYPE_BOOLEAN));
    dt1.getActionCols().add(brl);
    // Columns: Row#[0], Description[1], Condition[2]
    final GuidedDecisionTable52 dt2 = new GuidedDecisionTable52();
    final Pattern52 p2 = new Pattern52();
    p2.setBoundName("$f");
    p2.setFactType("Fact");
    final ConditionCol52 p2c1 = new ConditionCol52();
    p2c1.setFactField("field");
    p2.getChildColumns().add(p2c1);
    dt2.getConditions().add(p2);
    manager.link(dt1, dt2, (s, t) -> {
        assertEquals(2, s);
        assertEquals(2, t);
    });
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) IAction(org.drools.workbench.models.datamodel.rule.IAction) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) Test(org.junit.Test)

Example 12 with BRLActionVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.

the class DependentEnumsUtilities method getDependentColumnIndexes.

@Override
public Set<Integer> getDependentColumnIndexes(final Context context) {
    final int iBaseColIndex = context.getColumnIndex();
    final Set<Integer> dependentColumnIndexes = new HashSet<Integer>();
    // Get the column for the cell being edited
    final List<BaseColumn> allColumns = this.model.getExpandedColumns();
    final BaseColumn baseColumn = allColumns.get(iBaseColIndex);
    // Get values for all Constraints or Actions on the same pattern as the baseColumn
    if (baseColumn instanceof BRLConditionVariableColumn) {
        final BRLConditionVariableColumn baseBRLConditionColumn = (BRLConditionVariableColumn) baseColumn;
        final BRLConditionColumn brl = model.getBRLColumn(baseBRLConditionColumn);
        final RuleModel rm = new RuleModel();
        IPattern[] lhs = new IPattern[brl.getDefinition().size()];
        brl.getDefinition().toArray(lhs);
        rm.lhs = lhs;
        final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(rm, baseBRLConditionColumn.getVarName());
        List<ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
        // Add other variables values
        for (ValueHolder valueHolder : peerVariables) {
            switch(valueHolder.getType()) {
                case TEMPLATE_KEY:
                    if (oracle.isDependentEnum(baseBRLConditionColumn.getFactType(), baseBRLConditionColumn.getFactField(), valueHolder.getFieldName())) {
                        final BRLConditionVariableColumn vc = getConditionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
                        final int iCol = allColumns.indexOf(vc);
                        dependentColumnIndexes.add(iCol);
                    }
                    break;
            }
        }
    } else if (baseColumn instanceof BRLActionVariableColumn) {
        final BRLActionVariableColumn baseBRLActionColumn = (BRLActionVariableColumn) baseColumn;
        final BRLActionColumn brl = model.getBRLColumn(baseBRLActionColumn);
        final RuleModel rm = new RuleModel();
        IAction[] rhs = new IAction[brl.getDefinition().size()];
        brl.getDefinition().toArray(rhs);
        rm.rhs = rhs;
        final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(rm, baseBRLActionColumn.getVarName());
        List<ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
        // Add other variables values
        for (ValueHolder valueHolder : peerVariables) {
            switch(valueHolder.getType()) {
                case TEMPLATE_KEY:
                    if (oracle.isDependentEnum(baseBRLActionColumn.getFactType(), baseBRLActionColumn.getFactField(), valueHolder.getFieldName())) {
                        final BRLActionVariableColumn vc = getActionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
                        final int iCol = allColumns.indexOf(vc);
                        dependentColumnIndexes.add(iCol);
                    }
                    break;
            }
        }
    } else if (baseColumn instanceof ConditionCol52) {
        final ConditionCol52 baseConditionColumn = (ConditionCol52) baseColumn;
        final Pattern52 basePattern = this.model.getPattern(baseConditionColumn);
        for (ConditionCol52 cc : basePattern.getChildColumns()) {
            if (oracle.isDependentEnum(basePattern.getFactType(), baseConditionColumn.getFactField(), cc.getFactField())) {
                dependentColumnIndexes.add(allColumns.indexOf(cc));
            }
        }
    } else if (baseColumn instanceof ActionSetFieldCol52) {
        final ActionSetFieldCol52 baseActionColumn = (ActionSetFieldCol52) baseColumn;
        final Pattern52 basePattern = model.getConditionPattern(baseActionColumn.getBoundName());
        final String binding = baseActionColumn.getBoundName();
        for (ActionCol52 ac : this.model.getActionCols()) {
            if (ac instanceof ActionSetFieldCol52) {
                final ActionSetFieldCol52 asf = (ActionSetFieldCol52) ac;
                if (asf.getBoundName().equals(binding)) {
                    if (oracle.isDependentEnum(basePattern.getFactType(), baseActionColumn.getFactField(), asf.getFactField())) {
                        dependentColumnIndexes.add(allColumns.indexOf(ac));
                    }
                }
            }
        }
    } else if (baseColumn instanceof ActionInsertFactCol52) {
        final ActionInsertFactCol52 baseActionColumn = (ActionInsertFactCol52) baseColumn;
        final String binding = baseActionColumn.getBoundName();
        for (ActionCol52 ac : this.model.getActionCols()) {
            if (ac instanceof ActionInsertFactCol52) {
                final ActionInsertFactCol52 aif = (ActionInsertFactCol52) ac;
                if (aif.getBoundName().equals(binding)) {
                    if (oracle.isDependentEnum(baseActionColumn.getFactType(), baseActionColumn.getFactField(), aif.getFactField())) {
                        dependentColumnIndexes.add(allColumns.indexOf(ac));
                    }
                }
            }
        }
    }
    return dependentColumnIndexes;
}
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) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ValueHolder(org.drools.workbench.screens.guided.template.client.editor.RuleModelPeerVariableVisitor.ValueHolder) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) RuleModelPeerVariableVisitor(org.drools.workbench.screens.guided.template.client.editor.RuleModelPeerVariableVisitor) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) List(java.util.List) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) HashSet(java.util.HashSet)

Example 13 with BRLActionVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.

the class BRLActionColumnPlugin method convertInterpolationVariables.

private List<BRLActionVariableColumn> convertInterpolationVariables(Map<InterpolationVariable, Integer> ivs) {
    // If there are no variables add a boolean column to specify whether the fragment should apply
    if (ivs.isEmpty()) {
        BRLActionVariableColumn variable = new BRLActionVariableColumn("", DataType.TYPE_BOOLEAN);
        variable.setHeader(editingCol.getHeader());
        variable.setHideColumn(editingCol.isHideColumn());
        List<BRLActionVariableColumn> variables = new ArrayList<BRLActionVariableColumn>();
        variables.add(variable);
        return variables;
    }
    // Convert to columns for use in the Decision Table
    BRLActionVariableColumn[] variables = new BRLActionVariableColumn[ivs.size()];
    for (Map.Entry<InterpolationVariable, Integer> me : ivs.entrySet()) {
        InterpolationVariable iv = me.getKey();
        int index = me.getValue();
        BRLActionVariableColumn variable = new BRLActionVariableColumn(iv.getVarName(), iv.getDataType(), iv.getFactType(), iv.getFactField());
        variable.setHeader(editingCol.getHeader());
        variable.setHideColumn(editingCol.isHideColumn());
        variables[index] = variable;
    }
    // Convert the array into a mutable list (Arrays.toList provides an immutable list)
    List<BRLActionVariableColumn> variableList = new ArrayList<BRLActionVariableColumn>();
    for (BRLActionVariableColumn variable : variables) {
        variableList.add(variable);
    }
    return variableList;
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) ArrayList(java.util.ArrayList) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with BRLActionVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListenerTest method correctMergedConditionColumnHeaders.

@Test
public // https://issues.jboss.org/browse/RHBPMS-856
void correctMergedConditionColumnHeaders() {
    final ConversionResult result = new ConversionResult();
    final List<DataListener> listeners = new ArrayList<>();
    addModelField("org.test.Vehicle", "this", "org.test.Vehicle", DataType.TYPE_THIS);
    addModelField("org.test.Vehicle", "subRTO", String.class.getName(), DataType.TYPE_STRING);
    addModelField("org.test.Vehicle", "manufacturer", String.class.getName(), DataType.TYPE_STRING);
    addModelField("org.test.Vehicle", "model", String.class.getName(), DataType.TYPE_STRING);
    addModelField("org.test.Vehicle", "vehicleSegment", String.class.getName(), DataType.TYPE_STRING);
    addModelField("org.test.Vehicle", "vehicleAge", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    addModelField("org.test.Vehicle", "discount", Double.class.getName(), DataType.TYPE_NUMERIC_DOUBLE);
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    // Convert
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("RHBPMS-856 (Merged condition columns).xls");
    try {
        parser.parseFile(is);
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            fail(ioe.getMessage());
        }
    }
    // Check conversion results
    assertEquals(0, result.getMessages().size());
    // Check basics
    final List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("VehiclePremiumDiscount", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(9, columns.size());
    assertTrue(columns.get(0) instanceof RowNumberCol52);
    assertTrue(columns.get(1) instanceof DescriptionCol52);
    assertTrue(columns.get(2) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(3) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(4) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(5) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(6) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(7) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(8) instanceof BRLActionVariableColumn);
    // Check individual condition columns
    assertEquals(1, dtable.getConditions().size());
    assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
    BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
    assertEquals("Converted from ['RTO', 'Manufacturer', 'Model', 'Segment', 'Age Min', 'Age Max']", conditionCol0.getHeader());
    assertEquals(6, conditionCol0.getChildColumns().size());
    List<IPattern> conditionCol0definition = conditionCol0.getDefinition();
    assertEquals(1, conditionCol0definition.size());
    assertTrue(conditionCol0definition.get(0) instanceof FactPattern);
    FactPattern conditionCol0fp = (FactPattern) conditionCol0definition.get(0);
    assertEquals("Vehicle", conditionCol0fp.getFactType());
    assertEquals(6, conditionCol0fp.getNumberOfConstraints());
    // Field Constraint 1
    assertTrue(conditionCol0fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc0 = (SingleFieldConstraint) conditionCol0fp.getConstraint(0);
    assertEquals("subRTO", conditionCol0fpsfc0.getFieldName());
    assertEquals("==", conditionCol0fpsfc0.getOperator());
    assertEquals("param1", conditionCol0fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc0.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc0.getFieldType());
    // Field Constraint 2
    assertTrue(conditionCol0fp.getConstraint(1) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc1 = (SingleFieldConstraint) conditionCol0fp.getConstraint(1);
    assertEquals("manufacturer", conditionCol0fpsfc1.getFieldName());
    assertEquals("==", conditionCol0fpsfc1.getOperator());
    assertEquals("param2", conditionCol0fpsfc1.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc1.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc1.getFieldType());
    // Field Constraint 3
    assertTrue(conditionCol0fp.getConstraint(2) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc2 = (SingleFieldConstraint) conditionCol0fp.getConstraint(2);
    assertEquals("model", conditionCol0fpsfc2.getFieldName());
    assertEquals("==", conditionCol0fpsfc2.getOperator());
    assertEquals("param3", conditionCol0fpsfc2.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc2.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc2.getFieldType());
    // Field Constraint 4
    assertTrue(conditionCol0fp.getConstraint(3) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc3 = (SingleFieldConstraint) conditionCol0fp.getConstraint(3);
    assertEquals("vehicleSegment", conditionCol0fpsfc3.getFieldName());
    assertEquals("==", conditionCol0fpsfc3.getOperator());
    assertEquals("param4", conditionCol0fpsfc3.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc3.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc3.getFieldType());
    // Field Constraint 5
    assertTrue(conditionCol0fp.getConstraint(4) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc4 = (SingleFieldConstraint) conditionCol0fp.getConstraint(4);
    assertEquals("vehicleAge", conditionCol0fpsfc4.getFieldName());
    assertEquals("<=", conditionCol0fpsfc4.getOperator());
    assertEquals("param5", conditionCol0fpsfc4.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc4.getConstraintValueType());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0fpsfc4.getFieldType());
    // Field Constraint 6
    assertTrue(conditionCol0fp.getConstraint(5) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc5 = (SingleFieldConstraint) conditionCol0fp.getConstraint(5);
    assertEquals("vehicleAge", conditionCol0fpsfc5.getFieldName());
    assertEquals(">", conditionCol0fpsfc5.getOperator());
    assertEquals("param6", conditionCol0fpsfc5.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc5.getConstraintValueType());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0fpsfc5.getFieldType());
    // Field Constraint 1 - Variable 1
    BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
    assertEquals("param1", conditionCol0param0.getVarName());
    assertEquals("RTO", conditionCol0param0.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param0.getFieldType());
    assertEquals("Vehicle", conditionCol0param0.getFactType());
    assertEquals("subRTO", conditionCol0param0.getFactField());
    // Field Constraint 2 - Variable 2
    BRLConditionVariableColumn conditionCol0param1 = conditionCol0.getChildColumns().get(1);
    assertEquals("param2", conditionCol0param1.getVarName());
    assertEquals("Manufacturer", conditionCol0param1.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param1.getFieldType());
    assertEquals("Vehicle", conditionCol0param1.getFactType());
    assertEquals("manufacturer", conditionCol0param1.getFactField());
    // Field Constraint 3 - Variable 3
    BRLConditionVariableColumn conditionCol0param2 = conditionCol0.getChildColumns().get(2);
    assertEquals("param3", conditionCol0param2.getVarName());
    assertEquals("Model", conditionCol0param2.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param2.getFieldType());
    assertEquals("Vehicle", conditionCol0param2.getFactType());
    assertEquals("model", conditionCol0param2.getFactField());
    // Field Constraint 4 - Variable 4
    BRLConditionVariableColumn conditionCol0param3 = conditionCol0.getChildColumns().get(3);
    assertEquals("param4", conditionCol0param3.getVarName());
    assertEquals("Segment", conditionCol0param3.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param3.getFieldType());
    assertEquals("Vehicle", conditionCol0param3.getFactType());
    assertEquals("vehicleSegment", conditionCol0param3.getFactField());
    // Field Constraint 5 - Variable 5
    BRLConditionVariableColumn conditionCol0param4 = conditionCol0.getChildColumns().get(4);
    assertEquals("param5", conditionCol0param4.getVarName());
    assertEquals("Age Min", conditionCol0param4.getHeader());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0param4.getFieldType());
    assertEquals("Vehicle", conditionCol0param4.getFactType());
    assertEquals("vehicleAge", conditionCol0param4.getFactField());
    // Field Constraint 6 - Variable 6
    BRLConditionVariableColumn conditionCol0param5 = conditionCol0.getChildColumns().get(5);
    assertEquals("param6", conditionCol0param5.getVarName());
    assertEquals("Age Max", conditionCol0param5.getHeader());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0param5.getFieldType());
    assertEquals("Vehicle", conditionCol0param5.getFactType());
    assertEquals("vehicleAge", conditionCol0param5.getFactField());
    // Check individual action columns
    assertEquals(1, dtable.getActionCols().size());
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    BRLActionColumn actionCol0 = ((BRLActionColumn) dtable.getActionCols().get(0));
    assertEquals("Converted from ['Discount(%)']", actionCol0.getHeader());
    assertEquals(1, actionCol0.getChildColumns().size());
    List<IAction> actionCol0definition = actionCol0.getDefinition();
    assertEquals(1, actionCol0definition.size());
    assertTrue(actionCol0definition.get(0) instanceof ActionSetField);
    ActionSetField actionCol0asf0 = (ActionSetField) actionCol0definition.get(0);
    assertEquals("v", actionCol0asf0.getVariable());
    ActionFieldValue[] actionCol0asf0afvs = actionCol0asf0.getFieldValues();
    assertEquals(1, actionCol0asf0afvs.length);
    ActionFieldValue actionCol0asf0afv0 = actionCol0asf0afvs[0];
    assertEquals("discount", actionCol0asf0afv0.getField());
    assertEquals("param7", actionCol0asf0afv0.getValue());
    assertEquals(FieldNatureType.TYPE_TEMPLATE, actionCol0asf0afv0.getNature());
    assertEquals(DataType.TYPE_NUMERIC_DOUBLE, actionCol0asf0afv0.getType());
    // Action 1 - Variable 1
    BRLActionVariableColumn actionCol0param0 = actionCol0.getChildColumns().get(0);
    assertEquals("param7", actionCol0param0.getVarName());
    assertEquals("Discount(%)", actionCol0param0.getHeader());
    assertEquals(DataType.TYPE_NUMERIC_DOUBLE, actionCol0param0.getFieldType());
    assertEquals("Vehicle", actionCol0param0.getFactType());
    assertEquals("discount", actionCol0param0.getFactField());
    // Check data
    assertEquals(4, dtable.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "1", "ALL", "XYZ", "EL", "HighEnd", 1, 0, 1.75d }, dtable.getData().get(0)));
    assertTrue(isRowEquivalent(new Object[] { 2, "2", "ALL", "XYZ", "EL", "HighEnd", 5, 1, 2.00d }, dtable.getData().get(1)));
    assertTrue(isRowEquivalent(new Object[] { 3, "3", "ALL", "XYZ", "EL", "HighEnd", 7, 5, 2.00d }, dtable.getData().get(2)));
    assertTrue(isRowEquivalent(new Object[] { 4, "4", "ALL", "XYZ", "EL", "HighEnd", 10, 7, 1.00d }, dtable.getData().get(3)));
}
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) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) 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) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) IAction(org.drools.workbench.models.datamodel.rule.IAction) InputStream(java.io.InputStream) IOException(java.io.IOException) BigInteger(java.math.BigInteger) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) DataListener(org.drools.template.parser.DataListener) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 15 with BRLActionVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListenerTest method testMissingTemplateKeyValues_NonStringFields.

@Test
public // https://issues.jboss.org/browse/GUVNOR-2030
void testMissingTemplateKeyValues_NonStringFields() {
    final ConversionResult result = new ConversionResult();
    final List<DataListener> listeners = new ArrayList<DataListener>();
    addModelField("org.test.Client", "this", "org.test.Client", DataType.TYPE_THIS);
    addModelField("org.test.Client", "monthlyTransactions", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    // Convert
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("GUVNOR-2030 (DecisionTable).xls");
    try {
        parser.parseFile(is);
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            fail(ioe.getMessage());
        }
    }
    // Check conversion results
    assertEquals(0, result.getMessages().size());
    // Check basics
    final List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("Steps", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(5, columns.size());
    assertTrue(columns.get(0) instanceof RowNumberCol52);
    assertTrue(columns.get(1) instanceof DescriptionCol52);
    assertTrue(columns.get(2) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(3) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(4) instanceof BRLActionVariableColumn);
    // Check individual condition columns
    assertEquals(1, dtable.getConditions().size());
    assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
    // Column 1
    BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
    assertEquals("Converted from ['From', 'To']", conditionCol0.getHeader());
    assertEquals(2, conditionCol0.getChildColumns().size());
    List<IPattern> conditionCol0definition = conditionCol0.getDefinition();
    assertEquals(1, conditionCol0definition.size());
    assertTrue(conditionCol0definition.get(0) instanceof FactPattern);
    FactPattern conditionCol0fp = (FactPattern) conditionCol0definition.get(0);
    assertEquals("Client", conditionCol0fp.getFactType());
    assertEquals(2, conditionCol0fp.getNumberOfConstraints());
    assertTrue(conditionCol0fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc0 = (SingleFieldConstraint) conditionCol0fp.getConstraint(0);
    assertEquals("monthlyTransactions", conditionCol0fpsfc0.getFieldName());
    assertEquals(">=", conditionCol0fpsfc0.getOperator());
    assertEquals("param1", conditionCol0fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc0.getConstraintValueType());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0fpsfc0.getFieldType());
    assertTrue(conditionCol0fp.getConstraint(1) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc1 = (SingleFieldConstraint) conditionCol0fp.getConstraint(1);
    assertEquals("monthlyTransactions", conditionCol0fpsfc1.getFieldName());
    assertEquals("<=", conditionCol0fpsfc1.getOperator());
    assertEquals("param2", conditionCol0fpsfc1.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc1.getConstraintValueType());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0fpsfc1.getFieldType());
    // Column 1 - Variable 1
    BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
    assertEquals("param1", conditionCol0param0.getVarName());
    assertEquals("From", conditionCol0param0.getHeader());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0param0.getFieldType());
    assertEquals("Client", conditionCol0param0.getFactType());
    assertEquals("monthlyTransactions", conditionCol0param0.getFactField());
    // Column 1 - Variable 2
    BRLConditionVariableColumn conditionCol0param1 = conditionCol0.getChildColumns().get(1);
    assertEquals("param2", conditionCol0param1.getVarName());
    assertEquals("To", conditionCol0param1.getHeader());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0param1.getFieldType());
    assertEquals("Client", conditionCol0param1.getFactType());
    assertEquals("monthlyTransactions", conditionCol0param1.getFactField());
    // Check individual action columns
    assertEquals(1, dtable.getActionCols().size());
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    // Column 2
    BRLActionColumn actionCol0 = ((BRLActionColumn) dtable.getActionCols().get(0));
    assertEquals("Converted from ['Step']", actionCol0.getHeader());
    assertEquals(1, actionCol0.getChildColumns().size());
    List<IAction> actionCol0definition = actionCol0.getDefinition();
    assertEquals(1, actionCol0definition.size());
    assertTrue(actionCol0definition.get(0) instanceof FreeFormLine);
    FreeFormLine actionCol0ffl = (FreeFormLine) actionCol0definition.get(0);
    assertEquals("if (!$c.isPricingStepCustom() && ($c.getPricingStep() == null || $c.getPricingStep().compareTo(\"@{param3}\") < 0)) { modify($c) { setPricingStep(\"@{param3}\"); } };", actionCol0ffl.getText());
    // Check data
    assertEquals(1, dtable.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "Created from row 12", 0, 100, "A1" }, dtable.getData().get(0)));
}
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) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) 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) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) IAction(org.drools.workbench.models.datamodel.rule.IAction) InputStream(java.io.InputStream) IOException(java.io.IOException) BigInteger(java.math.BigInteger) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DataListener(org.drools.template.parser.DataListener) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Aggregations

BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)63 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)51 Test (org.junit.Test)38 ArrayList (java.util.ArrayList)27 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)27 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)21 IAction (org.drools.workbench.models.datamodel.rule.IAction)19 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)18 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)18 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)17 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)16 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)15 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)14 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)11 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)11 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)11 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 ExcelParser (org.drools.decisiontable.parser.xls.ExcelParser)10 DataListener (org.drools.template.parser.DataListener)10