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;
}
}
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;
}
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;
}
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());
}
}
}
}
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;
}
Aggregations