use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.
the class BRLConditionColumnPlugin method convertInterpolationVariables.
private List<BRLConditionVariableColumn> convertInterpolationVariables(Map<InterpolationVariable, Integer> ivs) {
// If there are no variables add a boolean column to specify whether the fragment should apply
if (ivs.isEmpty()) {
BRLConditionVariableColumn variable = new BRLConditionVariableColumn("", DataType.TYPE_BOOLEAN);
variable.setHeader(editingCol.getHeader());
variable.setHideColumn(editingCol.isHideColumn());
List<BRLConditionVariableColumn> variables = new ArrayList<BRLConditionVariableColumn>();
variables.add(variable);
return variables;
}
// Convert to columns for use in the Decision Table
BRLConditionVariableColumn[] variables = new BRLConditionVariableColumn[ivs.size()];
for (Map.Entry<InterpolationVariable, Integer> me : ivs.entrySet()) {
InterpolationVariable iv = me.getKey();
int index = me.getValue();
BRLConditionVariableColumn variable = new BRLConditionVariableColumn(iv.getVarName(), iv.getDataType(), iv.getFactType(), iv.getFactField());
variable.setHeader(editingCol.getHeader());
variable.setHideColumn(editingCol.isHideColumn());
variables[index] = variable;
}
// Convert the array into a mutable list (Arrays.toList provides an immutable list)
List<BRLConditionVariableColumn> variableList = new ArrayList<BRLConditionVariableColumn>();
for (BRLConditionVariableColumn variable : variables) {
variableList.add(variable);
}
return variableList;
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools by kiegroup.
the class GeneratorContextRuleModelVisitor method visitSingleFieldConstraint.
private void visitSingleFieldConstraint(final SingleFieldConstraintEBLeftSide sfexp) {
final String genericType = sfexp.getExpressionLeftSide().getGenericType();
String factType = sfexp.getExpressionLeftSide().getPreviousClassType();
if (factType == null) {
factType = sfexp.getExpressionLeftSide().getClassType();
}
final InterpolationVariable var = new InterpolationVariable(sfexp.getValue(), genericType, factType, sfexp.getFieldName());
if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfexp.getConstraintValueType() && !vars.contains(var)) {
vars.add(var);
} else {
hasNonTemplateOutput = true;
}
// Visit Connection constraints
if (sfexp.getConnectives() != null) {
for (int i = 0; i < sfexp.getConnectives().length; i++) {
final ConnectiveConstraint cc = sfexp.getConnectives()[i];
InterpolationVariable ccVar = new InterpolationVariable(cc.getValue(), genericType, factType, cc.getFieldName());
if (BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.contains(ccVar)) {
vars.add(ccVar);
} else {
hasNonTemplateOutput = true;
}
}
}
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools by kiegroup.
the class LHSGeneratorContext method setPattern.
private void setPattern(final IPattern pattern) {
this.pattern = pattern;
this.varsInScope.clear();
final Set<InterpolationVariable> vars = new HashSet<InterpolationVariable>();
final GeneratorContextRuleModelVisitor visitor = new GeneratorContextRuleModelVisitor(vars);
visitor.visit(pattern);
for (InterpolationVariable var : vars) {
varsInScope.add(var.getVarName());
}
hasNonTemplateOutput = visitor.hasNonTemplateOutput();
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools by kiegroup.
the class LHSGeneratorContext method setFieldConstraint.
private void setFieldConstraint(final FieldConstraint fieldConstraint) {
this.fieldConstraint = fieldConstraint;
this.varsInScope.clear();
final Set<InterpolationVariable> vars = new HashSet<InterpolationVariable>();
final GeneratorContextRuleModelVisitor visitor = new GeneratorContextRuleModelVisitor(vars);
visitor.visit(fieldConstraint);
for (InterpolationVariable var : vars) {
varsInScope.add(var.getVarName());
}
hasNonTemplateOutput = visitor.hasNonTemplateOutput();
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceImpl method marshalRuleHeader.
@Override
protected void marshalRuleHeader(final RuleModel model, final StringBuilder buf) {
// Append Template header
TemplateModel templateModel = (TemplateModel) model;
buf.append("template header\n");
InterpolationVariable[] interpolationVariables = templateModel.getInterpolationVariablesList();
if (interpolationVariables.length == 0) {
buf.append("test_var").append('\n');
} else {
for (InterpolationVariable var : interpolationVariables) {
buf.append(var.getVarName()).append('\n');
}
}
buf.append("\n");
// Append Package header
super.marshalPackageHeader(model, buf);
// Append Template definition
buf.append("\ntemplate \"").append(super.marshalRuleName(templateModel)).append("\"\n\n");
super.marshalRuleHeader(model, buf);
}
Aggregations