Search in sources :

Example 41 with BRLActionVariableColumn

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

the class DefaultGuidedDecisionTableLinkManagerTest method fieldConstraintWithActionBRLFragmentFieldWithTemplateKey.

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

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

        {
            add(aif);
        }
    });
    brl.getChildColumns().add(new BRLActionVariableColumn("$f", DataType.TYPE_STRING, "Fact", "field"));
    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 42 with BRLActionVariableColumn

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

the class GuidedDecisionTableFactory method makeTableWithBRLFragmentActionCol.

public static GuidedDecisionTable52 makeTableWithBRLFragmentActionCol(final String packageName, final Collection<Import> imports, final String tableName) {
    final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    dt.setPackageName(packageName);
    dt.getImports().getImports().addAll(imports);
    dt.setTableName(tableName);
    final BRLActionColumn brl = new BRLActionColumn();
    final ActionInsertFact ifc1 = new ActionInsertFact();
    ifc1.setFactType("Applicant");
    ifc1.setBoundName("$a");
    final ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("age");
    afv1.setValue("f1");
    ifc1.addFieldValue(afv1);
    final ActionInsertFact ifc2 = new ActionInsertFact();
    ifc2.setFactType("Mortgage");
    ifc2.setBoundName("$m");
    final ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv2.setField("amount");
    afv2.setValue("f2");
    ifc2.addFieldValue(afv2);
    final ActionSetField asf = new ActionSetField();
    asf.setVariable("$a");
    asf.addFieldValue(new ActionFieldValue("age", "33", DataType.TYPE_NUMERIC_INTEGER));
    final ActionUpdateField auf = new ActionUpdateField();
    asf.setVariable("$m");
    asf.addFieldValue(new ActionFieldValue("amount", "10000", DataType.TYPE_NUMERIC_INTEGER));
    brl.getDefinition().add(ifc1);
    brl.getDefinition().add(ifc2);
    brl.getChildColumns().add(new BRLActionVariableColumn("f1", DataType.TYPE_NUMERIC_INTEGER));
    brl.getChildColumns().add(new BRLActionVariableColumn("f2", DataType.TYPE_NUMERIC_INTEGER));
    brl.getDefinition().add(asf);
    brl.getDefinition().add(auf);
    dt.getConditions().add(brl);
    dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "33", "" } }));
    return dt;
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) 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)

Example 43 with BRLActionVariableColumn

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

the class DependentEnumsUtilities method getCurrentValueMap.

/**
 * Create a map of Field Values keyed on Field Names used by
 * SuggestionCompletionEngine.getEnums(String, String, Map<String, String>)
 * to drive dependent enumerations.
 *
 * @param context The Context of the cell being edited containing physical
 *                coordinate in the data-space.
 */
@Override
public Map<String, String> getCurrentValueMap(final Context context) {
    Map<String, String> currentValueMap = new HashMap<String, String>();
    final int iBaseRowIndex = context.getRowIndex();
    final int iBaseColIndex = context.getColumnIndex();
    final List<DTCellValue52> rowData = this.model.getData().get(iBaseRowIndex);
    // 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:
                    final BRLConditionVariableColumn vc = getConditionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
                    final int iCol = allColumns.indexOf(vc);
                    final DTCellValue52 dcv = rowData.get(iCol);
                    final String field = vc.getFactField();
                    currentValueMap.put(field, cellUtilities.asString(dcv));
                    break;
                case VALUE:
                    currentValueMap.put(valueHolder.getFieldName(), valueHolder.getValue());
            }
        }
    } 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:
                    final BRLActionVariableColumn vc = getActionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
                    final int iCol = allColumns.indexOf(vc);
                    final DTCellValue52 dcv = rowData.get(iCol);
                    final String field = vc.getFactField();
                    currentValueMap.put(field, cellUtilities.asString(dcv));
                    break;
                case VALUE:
                    currentValueMap.put(valueHolder.getFieldName(), valueHolder.getValue());
            }
        }
    } else if (baseColumn instanceof ConditionCol52) {
        final ConditionCol52 baseConditionColumn = (ConditionCol52) baseColumn;
        final Pattern52 basePattern = this.model.getPattern(baseConditionColumn);
        for (ConditionCol52 cc : basePattern.getChildColumns()) {
            final int iCol = allColumns.indexOf(cc);
            final DTCellValue52 dcv = rowData.get(iCol);
            currentValueMap.put(cc.getFactField(), cellUtilities.asString(dcv));
        }
    } else if (baseColumn instanceof ActionSetFieldCol52) {
        ActionSetFieldCol52 baseActionColumn = (ActionSetFieldCol52) baseColumn;
        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)) {
                    final int iCol = allColumns.indexOf(asf);
                    final DTCellValue52 dcv = rowData.get(iCol);
                    currentValueMap.put(asf.getFactField(), cellUtilities.asString(dcv));
                }
            }
        }
    } else if (baseColumn instanceof ActionInsertFactCol52) {
        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)) {
                    final int iCol = allColumns.indexOf(aif);
                    final DTCellValue52 dcv = rowData.get(iCol);
                    currentValueMap.put(aif.getFactField(), cellUtilities.asString(dcv));
                }
            }
        }
    }
    return currentValueMap;
}
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) HashMap(java.util.HashMap) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) 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)

Example 44 with BRLActionVariableColumn

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

the class BRLActionColumnSynchronizer method doMoveBRLFragment.

private void doMoveBRLFragment(final List<MoveColumnToMetaData> metaData) throws VetoException {
    final MoveColumnToMetaData md = metaData.get(0);
    final BRLActionVariableColumn srcModelColumn = (BRLActionVariableColumn) md.getColumn();
    final BRLActionColumn srcModelBRLFragment = model.getBRLColumn(srcModelColumn);
    if (srcModelBRLFragment == null) {
        throw new ModelSynchronizer.MoveVetoException();
    }
    final List<BRLActionVariableColumn> srcModelBRLFragmentColumns = srcModelBRLFragment.getChildColumns();
    final int srcModelBRLFragmentColumnsCount = srcModelBRLFragmentColumns.size();
    if (srcModelBRLFragmentColumnsCount == 0) {
        throw new ModelSynchronizer.MoveVetoException();
    }
    if (srcModelBRLFragmentColumnsCount != metaData.size()) {
        throw new ModelSynchronizer.MoveVetoException();
    }
    final int tgtColumnIndex = md.getTargetColumnIndex();
    final int tgtActionIndex = findTargetActionIndex(md);
    final List<BaseColumn> allModelColumns = model.getExpandedColumns();
    moveModelData(tgtColumnIndex, allModelColumns.indexOf(srcModelBRLFragmentColumns.get(0)), allModelColumns.indexOf(srcModelBRLFragmentColumns.get(0)) + srcModelBRLFragmentColumnsCount - 1);
    model.getActionCols().remove(srcModelBRLFragment);
    model.getActionCols().add(tgtActionIndex, srcModelBRLFragment);
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)

Example 45 with BRLActionVariableColumn

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

the class BRLActionColumnSynchronizer method append.

@Override
public void append(final ColumnMetaData metaData) throws VetoException {
    // Check operation is supported
    if (!handlesAppend(metaData)) {
        return;
    }
    final BRLActionColumn column = (BRLActionColumn) metaData.getColumn();
    model.getActionCols().add(column);
    for (BRLActionVariableColumn childModelColumn : column.getChildColumns()) {
        synchroniseAppendColumn(childModelColumn);
    }
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)

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