Search in sources :

Example 1 with LimitedEntryCol

use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol in project drools by kiegroup.

the class GuidedDTDRLPersistence method doActions.

void doActions(List<BaseColumn> allColumns, List<ActionCol52> actionCols, TemplateDataProvider rowDataProvider, List<DTCellValue52> row, RuleModel rm) {
    List<LabelledAction> actions = new ArrayList<LabelledAction>();
    for (ActionCol52 c : actionCols) {
        if (c instanceof LimitedEntryBRLActionColumn) {
            doAction(allColumns, (LimitedEntryBRLActionColumn) c, actions, rowDataProvider, row, rm);
        } else if (c instanceof BRLActionColumn) {
            doAction(allColumns, (BRLActionColumn) c, actions, rowDataProvider, row, rm);
        } else {
            int index = allColumns.indexOf(c);
            DTCellValue52 dcv = row.get(index);
            String cell = "";
            if (c instanceof LimitedEntryCol) {
                if (dcv.getBooleanValue() == true) {
                    LimitedEntryCol lec = (LimitedEntryCol) c;
                    cell = GuidedDTDRLUtilities.convertDTCellValueToString(lec.getValue());
                }
            } else {
                cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
            }
            if (validCell(cell, dcv.getDataType())) {
                if (c instanceof ActionWorkItemInsertFactCol52) {
                    doAction(actions, (ActionWorkItemInsertFactCol52) c, cell);
                } else if (c instanceof ActionInsertFactCol52) {
                    doAction(actions, (ActionInsertFactCol52) c, cell);
                } else if (c instanceof ActionWorkItemSetFieldCol52) {
                    doAction(actions, (ActionWorkItemSetFieldCol52) c, cell);
                } else if (c instanceof ActionSetFieldCol52) {
                    doAction(actions, (ActionSetFieldCol52) c, cell);
                } else if (c instanceof ActionRetractFactCol52) {
                    doAction(actions, cell);
                } else if (c instanceof ActionWorkItemCol52) {
                    doAction(actions, (ActionWorkItemCol52) c, cell);
                }
            }
        }
    }
    rm.rhs = new IAction[actions.size()];
    for (int i = 0; i < rm.rhs.length; i++) {
        rm.rhs[i] = actions.get(i).action;
    }
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ActionWorkItemInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemInsertFactCol52) ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ArrayList(java.util.ArrayList) ActionWorkItemSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemSetFieldCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol) LimitedEntryBRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryBRLActionColumn) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) LimitedEntryBRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryBRLActionColumn)

Example 2 with LimitedEntryCol

use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol in project drools by kiegroup.

the class GuidedDecisionTableUpgradeHelper3 method upgrade.

/**
 * Convert the Default Values in the Decision Table model
 *
 * @param source
 * @return The new DTModel
 */
public GuidedDecisionTable52 upgrade(GuidedDecisionTable52 source) {
    final GuidedDecisionTable52 destination = source;
    for (BaseColumn column : source.getExpandedColumns()) {
        DTColumnConfig52 dtColumn = null;
        if (column instanceof MetadataCol52) {
            dtColumn = (DTColumnConfig52) column;
        } else if (column instanceof AttributeCol52) {
            dtColumn = (DTColumnConfig52) column;
        } else if (column instanceof ConditionCol52) {
            dtColumn = (DTColumnConfig52) column;
        } else if (column instanceof ActionCol52) {
            dtColumn = (DTColumnConfig52) column;
        }
        if (dtColumn instanceof LimitedEntryCol) {
            dtColumn = null;
        }
        if (dtColumn instanceof BRLVariableColumn) {
            dtColumn = null;
        }
        if (dtColumn != null) {
            final String legacyDefaultValue = dtColumn.defaultValue;
            if (legacyDefaultValue != null) {
                dtColumn.setDefaultValue(new DTCellValue52(legacyDefaultValue));
                dtColumn.defaultValue = null;
            }
        }
    }
    return destination;
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) DTColumnConfig52(org.drools.workbench.models.guided.dtable.shared.model.DTColumnConfig52) BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol)

Example 3 with LimitedEntryCol

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

the class LimitedEntryDropDownManager method getCurrentValueMap.

@Override
public Map<String, String> getCurrentValueMap(Context context) {
    Map<String, String> currentValueMap = new HashMap<String, String>();
    final Pattern52 basePattern = context.getBasePattern();
    final BaseColumn baseColumn = context.getBaseColumn();
    // Get values for all Constraints or Actions on the same pattern as the baseColumn
    if (baseColumn instanceof ConditionCol52 && basePattern != null) {
        for (ConditionCol52 cc : basePattern.getChildColumns()) {
            if (cc instanceof LimitedEntryCol) {
                currentValueMap.put(cc.getFactField(), getValue((LimitedEntryCol) cc));
            }
        }
    } 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)) {
                    if (asf instanceof LimitedEntryCol) {
                        currentValueMap.put(asf.getFactField(), getValue((LimitedEntryCol) asf));
                    }
                }
            }
        }
    } 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)) {
                    if (aif instanceof LimitedEntryCol) {
                        currentValueMap.put(aif.getFactField(), getValue((LimitedEntryCol) aif));
                    }
                }
            }
        }
    }
    return currentValueMap;
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) HashMap(java.util.HashMap) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol)

Example 4 with LimitedEntryCol

use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol in project drools by kiegroup.

the class GuidedDTDRLPersistence method doCondition.

private void doCondition(List<BaseColumn> allColumns, Pattern52 pattern, List<IPattern> patterns, List<DTCellValue52> row, List<List<DTCellValue52>> data, RuleModel rm) {
    List<ConditionCol52> cols = pattern.getChildColumns();
    for (ConditionCol52 c : cols) {
        int index = allColumns.indexOf(c);
        DTCellValue52 dcv = row.get(index);
        String cell = "";
        if (c instanceof LimitedEntryCol) {
            if (Boolean.TRUE.equals(dcv.getBooleanValue())) {
                LimitedEntryCol lec = (LimitedEntryCol) c;
                DTCellValue52 value = lec.getValue();
                if (value != null) {
                    cell = GuidedDTDRLUtilities.convertDTCellValueToString(value);
                }
            }
        } else {
            cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
        }
        boolean isOtherwise = dcv.isOtherwise();
        boolean isValid = isOtherwise;
        // Otherwise values are automatically valid as they're constructed from the other rules
        if (!isOtherwise) {
            isValid = validCell(cell, dcv.getDataType());
        }
        // If operator is "== null" or "!= null" add constraint if table value is true
        if (c.getOperator() != null && (c.getOperator().equals("== null") || c.getOperator().equals("!= null"))) {
            isValid = Boolean.TRUE.equals(dcv.getBooleanValue());
        }
        if (isValid) {
            // get or create the pattern it belongs too
            IPattern ifp = findByFactPattern(patterns, pattern);
            // If the pattern does not exist create one suitable
            if (ifp == null) {
                FactPattern fp = new FactPattern(pattern.getFactType());
                fp.setBoundName(pattern.getBoundName());
                fp.setNegated(pattern.isNegated());
                fp.setWindow(pattern.getWindow());
                if (pattern.getEntryPointName() != null && pattern.getEntryPointName().length() > 0) {
                    FromEntryPointFactPattern fep = new FromEntryPointFactPattern();
                    fep.setEntryPointName(pattern.getEntryPointName());
                    fep.setFactPattern(fp);
                    patterns.add(fep);
                    ifp = fep;
                } else {
                    patterns.add(fp);
                    ifp = fp;
                }
            }
            // Extract the FactPattern from the IFactPattern
            FactPattern fp;
            if (ifp instanceof FactPattern) {
                fp = (FactPattern) ifp;
            } else if (ifp instanceof FromEntryPointFactPattern) {
                FromEntryPointFactPattern fep = (FromEntryPointFactPattern) ifp;
                fp = fep.getFactPattern();
            } else {
                throw new IllegalArgumentException("Inexpected IFactPattern implementation found.");
            }
            // Add the constraint from this cell
            switch(c.getConstraintValueType()) {
                case BaseSingleFieldConstraint.TYPE_LITERAL:
                case BaseSingleFieldConstraint.TYPE_RET_VALUE:
                    if (!isOtherwise) {
                        FieldConstraint fc = makeSingleFieldConstraint(c, cell);
                        fp.addConstraint(fc);
                    } else {
                        FieldConstraint fc = makeSingleFieldConstraint(c, allColumns, data);
                        fp.addConstraint(fc);
                    }
                    break;
                case BaseSingleFieldConstraint.TYPE_PREDICATE:
                    SingleFieldConstraint pred = new SingleFieldConstraint();
                    pred.setConstraintValueType(c.getConstraintValueType());
                    if (c.getFactField() != null && c.getFactField().indexOf("$param") > -1) {
                        // handle interpolation
                        pred.setValue(c.getFactField().replace("$param", cell));
                    } else {
                        pred.setValue(cell);
                    }
                    fp.addConstraint(pred);
                    break;
                default:
                    throw new IllegalArgumentException("Unknown constraintValueType: " + c.getConstraintValueType());
            }
        }
    }
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 5 with LimitedEntryCol

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

the class DTCellValueWidgetFactory method makeListBoxForColumn.

private ListBox makeListBoxForColumn(final DropDownData dd, final Pattern52 basePattern, final BaseColumn baseCondition, final DTCellValue52 dcv, final boolean isMultipleSelect) {
    final ListBox lb = makeListBox(dd, isMultipleSelect, dcv);
    // Wire up update handler
    lb.setEnabled(!isReadOnly);
    if (!isReadOnly) {
        lb.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                String value = null;
                if (lb.isMultipleSelect()) {
                    for (int i = 0; i < lb.getItemCount(); i++) {
                        if (lb.isItemSelected(i)) {
                            if (value == null) {
                                value = lb.getValue(i);
                            } else {
                                value = value + "," + lb.getValue(i);
                            }
                        }
                    }
                } else {
                    int index = lb.getSelectedIndex();
                    if (index > -1) {
                        // Set base column value
                        value = lb.getValue(index);
                    }
                }
                dcv.setStringValue(value);
                // Update any dependent enumerations
                final LimitedEntryDropDownManager.Context context = new LimitedEntryDropDownManager.Context(basePattern, baseCondition);
                Set<Integer> dependentColumnIndexes = dropDownManager.getDependentColumnIndexes(context);
                for (Integer iCol : dependentColumnIndexes) {
                    BaseColumn column = model.getExpandedColumns().get(iCol);
                    if (column instanceof LimitedEntryCol) {
                        ((LimitedEntryCol) column).setValue(null);
                    } else if (column instanceof DTColumnConfig52) {
                        ((DTColumnConfig52) column).setDefaultValue(null);
                    }
                }
            }
        });
    }
    return lb;
}
Also used : BigInteger(java.math.BigInteger) Set(java.util.Set) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) DTColumnConfig52(org.drools.workbench.models.guided.dtable.shared.model.DTColumnConfig52) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) LimitedEntryDropDownManager(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.LimitedEntryDropDownManager) ListBox(org.gwtbootstrap3.client.ui.ListBox) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol)

Aggregations

LimitedEntryCol (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol)7 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)5 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)3 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)3 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)3 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)2 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)2 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)2 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)2 ActionRetractFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52)2 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)2 DTColumnConfig52 (org.drools.workbench.models.guided.dtable.shared.model.DTColumnConfig52)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1