use of org.kie.dmn.model.api.LiteralExpression 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.LiteralExpression in project drools by kiegroup.
the class DTAnalysis method gapsAsMessages.
private Collection gapsAsMessages() {
List<DMNDTAnalysisMessage> results = new ArrayList<>();
if (!ddtaTable.getColIDsStringWithoutEnum().isEmpty()) {
List<String> names = ddtaTable.getColIDsStringWithoutEnum().stream().map(id -> sourceDT.getInput().get(id - 1)).map(InputClause::getInputExpression).map(LiteralExpression::getText).collect(Collectors.toList());
results.add(new DMNDTAnalysisMessage(this, Severity.WARN, MsgUtil.createMessage(Msg.DTANALYSIS_GAP_SKIPPED_BECAUSE_FREE_STRING, names), Msg.DTANALYSIS_GAP_SKIPPED_BECAUSE_FREE_STRING.getType()));
return results;
}
for (Hyperrectangle gap : gaps) {
results.add(new DMNDTAnalysisMessage(this, Severity.WARN, MsgUtil.createMessage(Msg.DTANALYSIS_GAP, gap.asHumanFriendly(ddtaTable)), Msg.DTANALYSIS_GAP.getType()));
}
return results;
}
use of org.kie.dmn.model.api.LiteralExpression in project drools by kiegroup.
the class XLS2DMNParser method appendDecisionDT.
private void appendDecisionDT(Definitions definitions, Map<String, DTHeaderInfo> headerInfos) {
for (DTHeaderInfo hi : headerInfos.values()) {
Decision decision = new TDecision();
decision.setName(hi.getSheetName());
decision.setId("d_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
InformationItem variable = new TInformationItem();
variable.setName(hi.getSheetName());
variable.setId("dvar_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
variable.setTypeRef(new QName("Any"));
decision.setVariable(variable);
for (String ri : hi.getRequiredInput()) {
InformationRequirement ir = new TInformationRequirement();
DMNElementReference er = new TDMNElementReference();
er.setHref("#id_" + CodegenStringUtil.escapeIdentifier(ri));
ir.setRequiredInput(er);
decision.getInformationRequirement().add(ir);
}
for (String ri : hi.getRequiredDecision()) {
InformationRequirement ir = new TInformationRequirement();
DMNElementReference er = new TDMNElementReference();
er.setHref("#d_" + CodegenStringUtil.escapeIdentifier(ri));
ir.setRequiredDecision(er);
decision.getInformationRequirement().add(ir);
}
DecisionTable dt = new TDecisionTable();
dt.setOutputLabel(hi.getSheetName());
dt.setId("ddt_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
dt.setHitPolicy(HitPolicy.ANY);
for (String ri : hi.getRequiredInput()) {
InputClause ic = new TInputClause();
ic.setLabel(ri);
LiteralExpression le = new TLiteralExpression();
le.setText(ri);
ic.setInputExpression(le);
dt.getInput().add(ic);
}
for (String rd : hi.getRequiredDecision()) {
InputClause ic = new TInputClause();
ic.setLabel(rd);
LiteralExpression le = new TLiteralExpression();
le.setText(rd);
ic.setInputExpression(le);
dt.getInput().add(ic);
}
OutputClause oc = new TOutputClause();
dt.getOutput().add(oc);
decision.setExpression(dt);
definitions.getDrgElement().add(decision);
}
}
use of org.kie.dmn.model.api.LiteralExpression 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.LiteralExpression in project drools by kiegroup.
the class LiteralExpressionConverter method assignAttributes.
@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
super.assignAttributes(reader, parent);
LiteralExpression le = (LiteralExpression) parent;
String exprLanguage = reader.getAttribute(EXPR_LANGUAGE);
le.setExpressionLanguage(exprLanguage);
}
Aggregations