use of org.kie.dmn.model.api.UnaryTests 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.UnaryTests in project drools by kiegroup.
the class DTSheetListener method newCell.
@Override
public void newCell(int row, int column, String value, int mergedColStart) {
if (row == 0) {
// TODO row 0 being the header.
return;
}
if (curRule == null) {
return;
}
if (value == null || value.isEmpty()) {
LOG.trace("ignoring row {}, col {} having value {}", row, column, value);
return;
}
if (column < headerInfo.gethIndex()) {
valueCheck(row, column, value);
UnaryTests ut = new TUnaryTests();
ut.setText(eValue(value));
curRule.getInputEntry().add(ut);
} else if (column == headerInfo.gethIndex()) {
valueCheck(row, column, value);
LiteralExpression le = new TLiteralExpression();
le.setText(eValue(value));
curRule.getOutputEntry().add(le);
} else {
LOG.trace("ignoring row {}, col {} having value {}", row, column, value);
}
}
use of org.kie.dmn.model.api.UnaryTests 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.UnaryTests in project drools by kiegroup.
the class ExpressionConverter method writeAttributes.
@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
super.writeAttributes(writer, parent);
Expression e = (Expression) parent;
if (!(e instanceof UnaryTests) && e.getTypeRef() != null) {
writer.addAttribute(TYPE_REF, MarshallingUtils.formatQName(e.getTypeRef(), e));
}
}
use of org.kie.dmn.model.api.UnaryTests 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