use of org.kie.dmn.model.api.DecisionRule in project drools by kiegroup.
the class DMNDTAnalyser method compileTableRules.
private void compileTableRules(DecisionTable dt, DDTATable ddtaTable) {
for (int jRowIdx = 0; jRowIdx < dt.getRule().size(); jRowIdx++) {
DecisionRule r = dt.getRule().get(jRowIdx);
DDTARule ddtaRule = new DDTARule();
int jColIdx = 0;
for (UnaryTests ie : r.getInputEntry()) {
ProcessedUnaryTest compileUnaryTests = (ProcessedUnaryTest) FEEL.compileUnaryTests(ie.getText(), FEEL.newCompilerContext());
UnaryTestInterpretedExecutableExpression interpreted = compileUnaryTests.getInterpreted();
UnaryTestListNode utln = (UnaryTestListNode) interpreted.getASTNode();
DDTAInputClause ddtaInputClause = ddtaTable.getInputs().get(jColIdx);
DDTAInputEntry ddtaInputEntry = new DDTAInputEntry(utln.getElements(), toIntervals(utln.getElements(), utln.isNegated(), ddtaInputClause.getDomainMinMax(), ddtaInputClause.getDiscreteValues(), jRowIdx + 1, jColIdx + 1));
for (Interval interval : ddtaInputEntry.getIntervals()) {
Interval domainMinMax = ddtaTable.getInputs().get(jColIdx).getDomainMinMax();
if (!domainMinMax.includes(interval)) {
throw new IllegalStateException(MsgUtil.createMessage(Msg.DTANALYSIS_ERROR_RULE_OUTSIDE_DOMAIN, jRowIdx + 1, interval, domainMinMax, jColIdx + 1));
}
}
ddtaRule.getInputEntry().add(ddtaInputEntry);
jColIdx++;
}
for (LiteralExpression oe : r.getOutputEntry()) {
ProcessedExpression compile = (ProcessedExpression) FEEL.compile(oe.getText(), FEEL.newCompilerContext());
InterpretedExecutableExpression interpreted = compile.getInterpreted();
BaseNode outputEntryNode = (BaseNode) interpreted.getASTNode();
Comparable<?> value = valueFromNode(outputEntryNode, outputClauseVisitor);
ddtaRule.getOutputEntry().add(value);
jColIdx++;
}
ddtaTable.addRule(ddtaRule);
}
}
use of org.kie.dmn.model.api.DecisionRule in project drools by kiegroup.
the class DTSheetListener method finishSheet.
@Override
public void finishSheet() {
List<DecisionRule> toBeRemoved = new ArrayList<>();
for (int i = 0; i < dt.getRule().size(); i++) {
DecisionRule rule = dt.getRule().get(i);
if (rule.getInputEntry().isEmpty()) {
toBeRemoved.add(rule);
}
}
dt.getRule().removeAll(toBeRemoved);
}
use of org.kie.dmn.model.api.DecisionRule in project drools by kiegroup.
the class DecisionTableConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
DecisionTable dt = (DecisionTable) parent;
for (InputClause i : dt.getInput()) {
writeChildrenNode(writer, context, i, INPUT);
}
for (OutputClause o : dt.getOutput()) {
writeChildrenNode(writer, context, o, OUTPUT);
}
for (DecisionRule r : dt.getRule()) {
writeChildrenNode(writer, context, r, RULE);
}
}
use of org.kie.dmn.model.api.DecisionRule in project drools by kiegroup.
the class DecisionRuleConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
DecisionRule dr = (DecisionRule) parent;
for (UnaryTests ie : dr.getInputEntry()) {
writeChildrenNode(writer, context, ie, INPUT_ENTRY);
}
for (LiteralExpression oe : dr.getOutputEntry()) {
writeChildrenNode(writer, context, oe, OUTPUT_ENTRY);
}
for (RuleAnnotation a : dr.getAnnotationEntry()) {
writeChildrenNode(writer, context, a, ANNOTATION_ENTRY);
}
}
use of org.kie.dmn.model.api.DecisionRule in project drools by kiegroup.
the class DecisionRuleConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
DecisionRule dr = (DecisionRule) parent;
for (UnaryTests ie : dr.getInputEntry()) {
writeChildrenNode(writer, context, ie, INPUT_ENTRY);
}
for (LiteralExpression oe : dr.getOutputEntry()) {
writeChildrenNode(writer, context, oe, OUTPUT_ENTRY);
}
for (RuleAnnotation a : dr.getAnnotationEntry()) {
writeChildrenNode(writer, context, a, ANNOTATION_ENTRY);
}
}
Aggregations