Search in sources :

Example 1 with GuidedDecisionTableLHSBuilder

use of org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListener method doCodeCell.

private void doCodeCell(final int row, final int column, final String value) {
    final ActionType actionType = getActionForColumn(row, column);
    if (actionType.getSourceBuilder() == null) {
        if (actionType.getCode() == Code.CONDITION) {
            GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableLHSBuilder(row - 2, column, "", this._parameterUtilities, this._conversionResult);
            this._sourceBuilders.add(sb);
            actionType.setSourceBuilder(sb);
        } else if (actionType.getCode() == Code.ACTION) {
            GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableRHSBuilder(row - 2, column, "", this._sourceBuilders, this._parameterUtilities, this._conversionResult);
            this._sourceBuilders.add(sb);
            actionType.setSourceBuilder(sb);
        }
    }
    if (value.trim().equals("") && (actionType.getCode() == Code.ACTION || actionType.getCode() == Code.CONDITION || actionType.getCode() == Code.METADATA)) {
        final String message = "Code description in cell " + RuleSheetParserUtil.rc2name(row, column) + " does not contain any code specification. It should!";
        this._conversionResult.addMessage(message, ConversionMessageType.ERROR);
    }
    actionType.addTemplate(row, column, value);
}
Also used : ActionType(org.drools.decisiontable.parser.ActionType) GuidedDecisionTableSourceBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder) GuidedDecisionTableRHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder) GuidedDecisionTableLHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder)

Example 2 with GuidedDecisionTableLHSBuilder

use of org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListener method doObjectTypeCell.

private void doObjectTypeCell(final int row, final int column, final String value, final int mergedColStart) {
    if (value.indexOf("$param") > -1 || value.indexOf("$1") > -1) {
        final String message = "It looks like you have snippets in the row that is " + "meant for object declarations." + " Please insert an additional row before the snippets, " + "at cell " + RuleSheetParserUtil.rc2name(row, column);
        this._conversionResult.addMessage(message, ConversionMessageType.ERROR);
    }
    ActionType actionType = getActionForColumn(row, column);
    if (mergedColStart == RuleSheetListener.NON_MERGED) {
        if (actionType.getCode() == Code.CONDITION) {
            GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableLHSBuilder(row - 1, column, value, this._parameterUtilities, this._conversionResult);
            this._sourceBuilders.add(sb);
            actionType.setSourceBuilder(sb);
        } else if (actionType.getCode() == Code.ACTION) {
            GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableRHSBuilder(row - 1, column, value, this._sourceBuilders, this._parameterUtilities, this._conversionResult);
            this._sourceBuilders.add(sb);
            actionType.setSourceBuilder(sb);
        }
    } else {
        if (column == mergedColStart) {
            if (actionType.getCode() == Code.CONDITION) {
                GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableLHSBuilder(row - 1, column, value, this._parameterUtilities, this._conversionResult);
                this._sourceBuilders.add(sb);
                actionType.setSourceBuilder(sb);
            } else if (actionType.getCode() == Code.ACTION) {
                GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableRHSBuilder(row - 1, column, value, this._sourceBuilders, this._parameterUtilities, this._conversionResult);
                this._sourceBuilders.add(sb);
                actionType.setSourceBuilder(sb);
            }
        } else {
            ActionType startOfMergeAction = getActionForColumn(row, mergedColStart);
            actionType.setSourceBuilder(startOfMergeAction.getSourceBuilder());
        }
    }
}
Also used : ActionType(org.drools.decisiontable.parser.ActionType) GuidedDecisionTableSourceBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder) GuidedDecisionTableRHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder) GuidedDecisionTableLHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder)

Example 3 with GuidedDecisionTableLHSBuilder

use of org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder 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)

Aggregations

GuidedDecisionTableLHSBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder)3 GuidedDecisionTableRHSBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder)3 GuidedDecisionTableSourceBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder)3 ActionType (org.drools.decisiontable.parser.ActionType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)1 IAction (org.drools.workbench.models.datamodel.rule.IAction)1 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)1 InterpolationVariable (org.drools.workbench.models.datamodel.rule.InterpolationVariable)1 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)1 RuleModelVisitor (org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor)1 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)1 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)1 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)1 BRLVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn)1 GuidedDecisionTableSourceBuilderIndirect (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilderIndirect)1