Search in sources :

Example 16 with BRLConditionVariableColumn

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

the class GuidedDecisionTablePopulater method makeBRLConditionVariableColumn.

private BRLConditionVariableColumn makeBRLConditionVariableColumn(final BRLConditionVariableColumn source, final InterpolationVariable iv) {
    final String varName = source.getVarName();
    final String dataType = iv.getDataType() == null ? DataType.TYPE_OBJECT : iv.getDataType();
    final String factType = iv.getFactType();
    final String factField = iv.getFactField();
    BRLConditionVariableColumn target;
    if (factType != null && factField != null) {
        target = new BRLConditionVariableColumn(varName, dataType, factType, factField);
    } else {
        target = new BRLConditionVariableColumn(varName, dataType);
    }
    target.setHeader(source.getHeader());
    return target;
}
Also used : BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 17 with BRLConditionVariableColumn

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

the class GuidedDecisionTablePopulater method addIndirectSourceBuildersColumns.

private void addIndirectSourceBuildersColumns() {
    final List<BRLVariableColumn> variableColumns = new ArrayList<BRLVariableColumn>();
    for (GuidedDecisionTableSourceBuilder sb : sourceBuilders) {
        if (sb instanceof GuidedDecisionTableSourceBuilderIndirect) {
            for (BRLVariableColumn variableColumn : ((GuidedDecisionTableSourceBuilderIndirect) sb).getVariableColumns()) {
                variableColumns.add(variableColumn);
            }
        }
    }
    // Convert the DRL to a RuleModel from which we construct BRLFragment columns
    final StringBuilder rule = new StringBuilder();
    if (!(dmo.getPackageName() == null || dmo.getPackageName().isEmpty())) {
        rule.append("package ").append(dmo.getPackageName()).append("\n");
    }
    rule.append("rule 'temp' \n").append("when \n");
    for (GuidedDecisionTableSourceBuilder sb : sourceBuilders) {
        if (sb instanceof GuidedDecisionTableLHSBuilder) {
            rule.append(sb.getResult());
        }
    }
    rule.append("\nthen \n");
    for (GuidedDecisionTableSourceBuilder sb : sourceBuilders) {
        if (sb instanceof GuidedDecisionTableRHSBuilder) {
            rule.append(sb.getResult());
        }
    }
    rule.append("end");
    final RuleModel rm = RuleModelDRLPersistenceImpl.getInstance().unmarshal(rule.toString(), Collections.emptyList(), dmo);
    if (rm.lhs != null) {
        for (IPattern pattern : rm.lhs) {
            final BRLConditionColumn column = new BRLConditionColumn();
            column.getDefinition().add(pattern);
            dtable.getConditions().add(column);
            final Map<InterpolationVariable, Integer> templateKeys = new HashMap<>();
            final RuleModelVisitor rmv = new RuleModelVisitor(templateKeys);
            rmv.visit(pattern);
            final List<InterpolationVariable> ivs = new ArrayList<>(templateKeys.keySet());
            for (BRLVariableColumn variableColumn : variableColumns) {
                final Iterator<InterpolationVariable> ivsIts = ivs.iterator();
                while (ivsIts.hasNext()) {
                    final InterpolationVariable iv = ivsIts.next();
                    if (iv.getVarName().equals(variableColumn.getVarName())) {
                        final BRLConditionVariableColumn source = (BRLConditionVariableColumn) variableColumn;
                        final BRLConditionVariableColumn target = makeBRLConditionVariableColumn(source, iv);
                        column.getChildColumns().add(target);
                        ivsIts.remove();
                    }
                }
            }
            if (column.getChildColumns().isEmpty()) {
                setZeroParameterConditionColumnHeader(column, variableColumns);
            } else {
                setCompositeColumnHeader(column);
            }
        }
    }
    if (rm.rhs != null) {
        for (IAction action : rm.rhs) {
            final BRLActionColumn column = new BRLActionColumn();
            column.getDefinition().add(action);
            dtable.getActionCols().add(column);
            if (action instanceof ActionRetractFact) {
                final ActionRetractFact arf = (ActionRetractFact) action;
                createActionRetractFactChildColumns(arf, column, variableColumns);
            } else {
                createRHSChildColumns(rm, action, column, variableColumns);
            }
            if (column.getChildColumns().isEmpty()) {
                setZeroParameterActionColumnHeader(column, variableColumns);
            } else {
                setCompositeColumnHeader(column);
            }
        }
    }
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) GuidedDecisionTableRHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder) IAction(org.drools.workbench.models.datamodel.rule.IAction) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GuidedDecisionTableSourceBuilderIndirect(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilderIndirect) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) GuidedDecisionTableSourceBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder) RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) GuidedDecisionTableLHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder)

Example 18 with BRLConditionVariableColumn

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

the class GuidedDecisionTablePopulater method setZeroParameterConditionColumnHeader.

private void setZeroParameterConditionColumnHeader(final BRLConditionColumn column, final List<BRLVariableColumn> allVariableColumns) {
    final BRLConditionVariableColumn source = findZeroParameterSourceConditionColumn(allVariableColumns);
    final BRLConditionVariableColumn target = new BRLConditionVariableColumn("", DataType.TYPE_BOOLEAN);
    column.getChildColumns().add(target);
    setZeroParameterColumnHeader(column, source, target);
}
Also used : BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 19 with BRLConditionVariableColumn

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

the class GuidedDecisionTableLHSBuilder method addBRLFragmentColumn.

private List<BRLVariableColumn> addBRLFragmentColumn(final ParameterizedValueBuilder vb) {
    final List<BRLVariableColumn> variableColumns = new ArrayList<BRLVariableColumn>();
    for (String parameter : vb.getParameters()) {
        final BRLConditionVariableColumn parameterColumn = new BRLConditionVariableColumn(parameter, DataType.TYPE_OBJECT);
        variableColumns.add(parameterColumn);
    }
    // Store DRL fragment for use by GuidedDecisionTableRHSBuilder
    drlFragments.add(vb.getTemplate());
    return variableColumns;
}
Also used : BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) ArrayList(java.util.ArrayList) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 20 with BRLConditionVariableColumn

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

the class BRLConditionColumnSynchronizer method doMoveBRLFragment.

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

Aggregations

BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)69 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)53 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)28 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)24 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)23 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)23 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)23 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)23 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)18 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)15 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)15 IOException (java.io.IOException)11 InputStream (java.io.InputStream)11 ExcelParser (org.drools.decisiontable.parser.xls.ExcelParser)11 DataListener (org.drools.template.parser.DataListener)11 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)11 ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)11 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)11