use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class ConditionBuilder method build.
public Condition build() throws BuildException {
PortablePreconditions.checkNotNull("conditionCol52", conditionCol52);
PortablePreconditions.checkNotNull("columnIndex", columnIndex);
PortablePreconditions.checkNotNull("row", row);
if (conditionCol52 instanceof BRLConditionVariableColumn) {
return builderFactory.getBRLConditionBuilder().with((BRLConditionVariableColumn) conditionCol52).with(row.get(columnIndex)).with(columnIndex).build();
} else {
PortablePreconditions.checkNotNull("rule", rule);
final Pattern pattern = builderFactory.getPatternResolver().with(rule).with(columnIndex).resolve();
return builderFactory.getFieldConditionsBuilder().with(pattern).with(conditionCol52).with(getRealCellValue(conditionCol52, row.get(columnIndex))).with(columnIndex).build();
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class DecisionTableAnalyzer method getColumnIndex.
private int getColumnIndex(final BaseColumn baseColumn) {
List<BaseColumn> cols = model.getExpandedColumns();
final int indexOf = cols.indexOf(baseColumn);
if (indexOf < 0) {
if (baseColumn instanceof BRLConditionColumn) {
for (final BaseColumn column : model.getExpandedColumns()) {
if (column instanceof BRLConditionVariableColumn) {
if (((BRLConditionColumn) baseColumn).getChildColumns().contains(column)) {
return model.getExpandedColumns().indexOf(column);
}
}
}
throw new IllegalArgumentException("Could not find BRLConditionColumn: " + baseColumn.toString());
}
if (baseColumn instanceof BRLActionColumn) {
for (final BaseColumn column : model.getExpandedColumns()) {
if (column instanceof BRLActionVariableColumn) {
if (((BRLActionColumn) baseColumn).getChildColumns().contains(column)) {
return model.getExpandedColumns().indexOf(column);
}
}
}
throw new IllegalArgumentException("Could not find BRLActionColumn: " + baseColumn.toString());
} else if (baseColumn instanceof BRLVariableColumn) {
return model.getExpandedColumns().indexOf(model.getBRLColumn((BRLVariableColumn) baseColumn));
} else {
throw new IllegalArgumentException("Could not find baseColumn: " + baseColumn.toString());
}
} else {
return indexOf;
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class GuidedDecisionTableFactory method makeTableWithBRLFragmentConditionColWithPredicate.
public static GuidedDecisionTable52 makeTableWithBRLFragmentConditionColWithPredicate(final String packageName, final Collection<Import> imports, final String tableName) {
final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setPackageName(packageName);
dt.getImports().getImports().addAll(imports);
dt.setTableName(tableName);
final BRLConditionColumn brl = new BRLConditionColumn();
final FactPattern fp1 = new FactPattern();
fp1.setFactType("Applicant");
final SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE);
sfc1.setValue("age = 45");
fp1.addConstraint(sfc1);
brl.getDefinition().add(fp1);
brl.getChildColumns().add(new BRLConditionVariableColumn("f1", DataType.TYPE_BOOLEAN));
dt.getConditions().add(brl);
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", true } }));
return dt;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class GuidedDecisionTableFactory method makeTableWithBRLFragmentConditionCol.
public static GuidedDecisionTable52 makeTableWithBRLFragmentConditionCol(final String packageName, final Collection<Import> imports, final String tableName) {
final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setPackageName(packageName);
dt.getImports().getImports().addAll(imports);
dt.setTableName(tableName);
final BRLConditionColumn brl = new BRLConditionColumn();
final FactPattern fp1 = new FactPattern();
fp1.setFactType("Applicant");
final SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setFactType("Applicant");
sfc1.setOperator("==");
sfc1.setFieldName("age");
sfc1.setValue("f1");
fp1.addConstraint(sfc1);
final FactPattern fp2 = new FactPattern();
fp2.setFactType("Mortgage");
final SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setFactType("Mortgage");
sfc2.setOperator("==");
sfc2.setFieldName("amount");
sfc2.setValue("f2");
fp2.addConstraint(sfc2);
brl.getDefinition().add(fp1);
brl.getDefinition().add(fp2);
brl.getChildColumns().add(new BRLConditionVariableColumn("f1", DataType.TYPE_NUMERIC_INTEGER));
brl.getChildColumns().add(new BRLConditionVariableColumn("f2", DataType.TYPE_NUMERIC_INTEGER));
dt.getConditions().add(brl);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "33", "" } }));
return dt;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class DependentEnumsUtilities method getDependentColumnIndexes.
@Override
public Set<Integer> getDependentColumnIndexes(final Context context) {
final int iBaseColIndex = context.getColumnIndex();
final Set<Integer> dependentColumnIndexes = new HashSet<Integer>();
// Get the column for the cell being edited
final List<BaseColumn> allColumns = this.model.getExpandedColumns();
final BaseColumn baseColumn = allColumns.get(iBaseColIndex);
// Get values for all Constraints or Actions on the same pattern as the baseColumn
if (baseColumn instanceof BRLConditionVariableColumn) {
final BRLConditionVariableColumn baseBRLConditionColumn = (BRLConditionVariableColumn) baseColumn;
final BRLConditionColumn brl = model.getBRLColumn(baseBRLConditionColumn);
final RuleModel rm = new RuleModel();
IPattern[] lhs = new IPattern[brl.getDefinition().size()];
brl.getDefinition().toArray(lhs);
rm.lhs = lhs;
final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(rm, baseBRLConditionColumn.getVarName());
List<ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
// Add other variables values
for (ValueHolder valueHolder : peerVariables) {
switch(valueHolder.getType()) {
case TEMPLATE_KEY:
if (oracle.isDependentEnum(baseBRLConditionColumn.getFactType(), baseBRLConditionColumn.getFactField(), valueHolder.getFieldName())) {
final BRLConditionVariableColumn vc = getConditionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
final int iCol = allColumns.indexOf(vc);
dependentColumnIndexes.add(iCol);
}
break;
}
}
} else if (baseColumn instanceof BRLActionVariableColumn) {
final BRLActionVariableColumn baseBRLActionColumn = (BRLActionVariableColumn) baseColumn;
final BRLActionColumn brl = model.getBRLColumn(baseBRLActionColumn);
final RuleModel rm = new RuleModel();
IAction[] rhs = new IAction[brl.getDefinition().size()];
brl.getDefinition().toArray(rhs);
rm.rhs = rhs;
final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(rm, baseBRLActionColumn.getVarName());
List<ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
// Add other variables values
for (ValueHolder valueHolder : peerVariables) {
switch(valueHolder.getType()) {
case TEMPLATE_KEY:
if (oracle.isDependentEnum(baseBRLActionColumn.getFactType(), baseBRLActionColumn.getFactField(), valueHolder.getFieldName())) {
final BRLActionVariableColumn vc = getActionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
final int iCol = allColumns.indexOf(vc);
dependentColumnIndexes.add(iCol);
}
break;
}
}
} else if (baseColumn instanceof ConditionCol52) {
final ConditionCol52 baseConditionColumn = (ConditionCol52) baseColumn;
final Pattern52 basePattern = this.model.getPattern(baseConditionColumn);
for (ConditionCol52 cc : basePattern.getChildColumns()) {
if (oracle.isDependentEnum(basePattern.getFactType(), baseConditionColumn.getFactField(), cc.getFactField())) {
dependentColumnIndexes.add(allColumns.indexOf(cc));
}
}
} else if (baseColumn instanceof ActionSetFieldCol52) {
final ActionSetFieldCol52 baseActionColumn = (ActionSetFieldCol52) baseColumn;
final Pattern52 basePattern = model.getConditionPattern(baseActionColumn.getBoundName());
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 (oracle.isDependentEnum(basePattern.getFactType(), baseActionColumn.getFactField(), asf.getFactField())) {
dependentColumnIndexes.add(allColumns.indexOf(ac));
}
}
}
}
} else if (baseColumn instanceof ActionInsertFactCol52) {
final 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 (oracle.isDependentEnum(baseActionColumn.getFactType(), baseActionColumn.getFactField(), aif.getFactField())) {
dependentColumnIndexes.add(allColumns.indexOf(ac));
}
}
}
}
}
return dependentColumnIndexes;
}
Aggregations