use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class GuidedDecisionTablePopulater method makeBRLConditionVariableColumn.
private BRLConditionVariableColumn makeBRLConditionVariableColumn(final BRLConditionVariableColumn source, final InterpolationVariable iv) {
final String varName = source.getVarName();
final String dataType = iv.getDataType() == null ? DataType.TYPE_OBJECT : iv.getDataType();
final String factType = iv.getFactType();
final String factField = iv.getFactField();
BRLConditionVariableColumn target;
if (factType != null && factField != null) {
target = new BRLConditionVariableColumn(varName, dataType, factType, factField);
} else {
target = new BRLConditionVariableColumn(varName, dataType);
}
target.setHeader(source.getHeader());
return target;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn 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);
}
}
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class GuidedDecisionTablePopulater method setZeroParameterConditionColumnHeader.
private void setZeroParameterConditionColumnHeader(final BRLConditionColumn column, final List<BRLVariableColumn> allVariableColumns) {
final BRLConditionVariableColumn source = findZeroParameterSourceConditionColumn(allVariableColumns);
final BRLConditionVariableColumn target = new BRLConditionVariableColumn("", DataType.TYPE_BOOLEAN);
column.getChildColumns().add(target);
setZeroParameterColumnHeader(column, source, target);
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class GuidedDecisionTableLHSBuilder method addBRLFragmentColumn.
private List<BRLVariableColumn> addBRLFragmentColumn(final ParameterizedValueBuilder vb) {
final List<BRLVariableColumn> variableColumns = new ArrayList<BRLVariableColumn>();
for (String parameter : vb.getParameters()) {
final BRLConditionVariableColumn parameterColumn = new BRLConditionVariableColumn(parameter, DataType.TYPE_OBJECT);
variableColumns.add(parameterColumn);
}
// Store DRL fragment for use by GuidedDecisionTableRHSBuilder
drlFragments.add(vb.getTemplate());
return variableColumns;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizer method doMoveBRLFragment.
private void doMoveBRLFragment(final List<MoveColumnToMetaData> metaData) throws VetoException {
final MoveColumnToMetaData md = metaData.get(0);
final BRLConditionVariableColumn srcModelColumn = (BRLConditionVariableColumn) md.getColumn();
final BRLConditionColumn srcModelBRLFragment = model.getBRLColumn(srcModelColumn);
if (srcModelBRLFragment == null) {
throw new ModelSynchronizer.MoveVetoException();
}
final List<BRLConditionVariableColumn> srcModelBRLFragmentColumns = srcModelBRLFragment.getChildColumns();
final int srcModelPatternConditionColumnCount = srcModelBRLFragmentColumns.size();
if (srcModelPatternConditionColumnCount == 0) {
throw new ModelSynchronizer.MoveVetoException();
}
if (srcModelPatternConditionColumnCount != metaData.size()) {
throw new ModelSynchronizer.MoveVetoException();
}
final int tgtColumnIndex = md.getTargetColumnIndex();
final int tgtPatternIndex = findTargetPatternIndex(md);
final List<BaseColumn> allModelColumns = model.getExpandedColumns();
moveModelData(tgtColumnIndex, allModelColumns.indexOf(srcModelBRLFragmentColumns.get(0)), allModelColumns.indexOf(srcModelBRLFragmentColumns.get(0)) + srcModelPatternConditionColumnCount - 1);
model.getConditions().remove(srcModelBRLFragment);
model.getConditions().add(tgtPatternIndex, srcModelBRLFragment);
}
Aggregations