Search in sources :

Example 1 with ValuePlaceHolder

use of org.drools.workbench.screens.guided.dtable.backend.server.conversion.util.ValuePlaceHolder in project drools-wb by kiegroup.

the class BRLColumnSubHeaderBuilderByPatterns method buildBrlActions.

@Override
public void buildBrlActions(final BRLActionColumn brlColumn) {
    final Iterator<IAction> definitionIterator = brlColumn.getDefinition().iterator();
    while (definitionIterator.hasNext()) {
        final IAction iAction = definitionIterator.next();
        final Iterator<ValuePlaceHolder> valuesIterator = columnContext.getVariablesInOrderOfUse(iAction).iterator();
        final String boundName = getBoundName(iAction);
        if (iAction instanceof ActionInsertFact) {
            final ActionInsertFact actionInsertFact = (ActionInsertFact) iAction;
            subHeaderBuilder.getColumnContext().put(brlColumn, FromTo.makePlaceHolder(dtable.getExpandedColumns().indexOf(brlColumn.getChildColumns().get(0)), subHeaderBuilder.getTargetColumnIndex()));
            final boolean madeInsert = subHeaderBuilder.makeInsert(boundName, actionInsertFact.getFactType());
            if (madeInsert && fieldValuesLength((ActionInsertFact) iAction) != 0) {
                subHeaderBuilder.incrementTargetIndex();
            }
        } else if (iAction instanceof ActionCallMethod && hasNoVariables(valuesIterator)) {
            subHeaderBuilder.addMethodCallWithoutParameters(brlColumn.getHeader(), (ActionCallMethod) iAction);
            updateColumnContext(brlColumn, brlColumn.getChildColumns().get(0));
        }
        while (valuesIterator.hasNext()) {
            final ValuePlaceHolder value = valuesIterator.next();
            final ActionCol52 childColumn = getChildActionColumn(value, brlColumn.getChildColumns());
            if (iAction instanceof ActionCallMethod) {
                final StringBuilder params = new StringBuilder();
                final int methodParameterCount = fieldValuesLength((ActionCallMethod) iAction);
                if (methodParameterCount == 1) {
                    params.append(wrapParameter(childColumn, "$param"));
                } else if (valuesIterator.hasNext()) {
                    if (isThereJustOneVariableInParameters(((ActionCallMethod) iAction).getFieldValues())) {
                        params.append(wrapParameter(childColumn, "$param"));
                    } else {
                        params.append(wrapParameter(childColumn, "$1"));
                    }
                    for (int i = 1; i < methodParameterCount; i++) {
                        final ValuePlaceHolder next = valuesIterator.next();
                        params.append(", ");
                        switch(next.getType()) {
                            case VARIABLE:
                                params.append(wrapParameter(childColumn, "$" + (i + 1)));
                                updateColumnContext(brlColumn, getChildActionColumn(next, brlColumn.getChildColumns()));
                                break;
                            case VALUE:
                                params.append(next.getValue());
                                break;
                        }
                    }
                }
                subHeaderBuilder.addMethodCallWithParameters(brlColumn.getHeader(), (ActionCallMethod) iAction, params.toString());
                updateColumnContext(brlColumn, childColumn);
                if (valuesIterator.hasNext()) {
                    subHeaderBuilder.incrementTargetIndex();
                }
            } else {
                if (childColumn instanceof BRLActionVariableColumn) {
                    addBRLActionVariableColumn(brlColumn, boundName, (BRLActionVariableColumn) childColumn);
                    updateColumnContext(brlColumn, childColumn);
                    if (valuesIterator.hasNext()) {
                        subHeaderBuilder.incrementTargetIndex();
                    }
                }
            }
        }
        if (definitionIterator.hasNext()) {
            subHeaderBuilder.incrementTargetIndex();
        }
    }
}
Also used : IAction(org.drools.workbench.models.datamodel.rule.IAction) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ValuePlaceHolder(org.drools.workbench.screens.guided.dtable.backend.server.conversion.util.ValuePlaceHolder) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)

Aggregations

ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)1 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)1 IAction (org.drools.workbench.models.datamodel.rule.IAction)1 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)1 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)1 ValuePlaceHolder (org.drools.workbench.screens.guided.dtable.backend.server.conversion.util.ValuePlaceHolder)1