use of org.drools.model.patterns.CompositePatterns in project drools by kiegroup.
the class ViewPatternBuilder method apply.
public CompositePatterns apply(RuleItemBuilder<?>[] viewItemBuilders) {
List<RuleItem> ruleItems = Stream.of(viewItemBuilders).map(RuleItemBuilder::get).collect(toList());
Iterator<RuleItem> ruleItemIterator = ruleItems.iterator();
List<Condition> conditions = new ArrayList<>();
Map<String, Consequence> consequences = new LinkedHashMap<>();
while (ruleItemIterator.hasNext()) {
RuleItem ruleItem = ruleItemIterator.next();
if (ruleItem instanceof Consequence) {
Consequence consequence = (Consequence) ruleItem;
String name = ruleItemIterator.hasNext() ? generateName("consequence") : RuleImpl.DEFAULT_CONSEQUENCE_NAME;
consequences.put(name, consequence);
conditions.add(new NamedConsequenceImpl(name, consequence.isBreaking()));
continue;
}
if (ruleItem instanceof ConditionalConsequence) {
conditions.add(createConditionalNamedConsequence(consequences, (ConditionalConsequence) ruleItem));
continue;
}
conditions.add(ruleItem2Condition(ruleItem));
}
return new CompositePatterns(Condition.Type.AND, conditions, consequences);
}
use of org.drools.model.patterns.CompositePatterns in project drools by kiegroup.
the class KiePackagesBuilder method recursivelyAddConditions.
private void recursivelyAddConditions(RuleContext ctx, GroupElement group, GroupElement allSubConditions, Condition c) {
if (c instanceof CompositePatterns) {
c.getSubConditions().forEach(sc -> recursivelyAddConditions(ctx, group, allSubConditions, sc));
} else if (c instanceof ExistentialPatternImpl) {
if (c.getType() == Condition.Type.FORALL) {
allSubConditions.addChild(buildForAll(ctx, allSubConditions, c));
} else {
GroupElement existGroupElement = new GroupElement(conditionToGroupElementType(c.getType()));
allSubConditions.addChild(existGroupElement);
recursivelyAddConditions(ctx, existGroupElement, existGroupElement, c.getSubConditions().iterator().next());
}
} else if (c instanceof PatternImpl) {
org.drools.model.Pattern pattern = (org.drools.model.Pattern<?>) c;
RuleConditionElement rce = buildPattern(ctx, allSubConditions, pattern);
if (ctx.getAccumulateSource(pattern.getPatternVariable()) == null) {
allSubConditions.addChild(rce);
}
} else if (c instanceof AccumulatePattern) {
RuleConditionElement rce = buildAccumulate(ctx, group, (AccumulatePattern) c);
if (rce != null) {
allSubConditions.addChild(rce);
}
} else if (c instanceof EvalImpl) {
allSubConditions.addChild(buildEval(ctx, (EvalImpl) c));
}
}
Aggregations