use of org.kie.dmn.model.api.OutputClause in project drools by kiegroup.
the class DMNDTAnalyser method compileTableOutputClauses.
private void compileTableOutputClauses(DMNModel model, DecisionTable dt, DDTATable ddtaTable) {
for (int jColIdx = 0; jColIdx < dt.getOutput().size(); jColIdx++) {
OutputClause oe = dt.getOutput().get(jColIdx);
Interval infDomain = new Interval(RangeBoundary.CLOSED, Interval.NEG_INF, Interval.POS_INF, RangeBoundary.CLOSED, 0, jColIdx + 1);
String allowedValues = null;
if (oe.getOutputValues() != null) {
allowedValues = oe.getOutputValues().getText();
} else {
QName outputTypeRef = (oe.getTypeRef() == null && dt.getOutput().size() == 1) ? dt.getTypeRef() : oe.getTypeRef();
if (outputTypeRef != null) {
QName typeRef = DMNCompilerImpl.getNamespaceAndName(dt, ((DMNModelImpl) model).getImportAliasesForNS(), outputTypeRef, model.getNamespace());
allowedValues = findAllowedValues(model, typeRef);
}
}
if (allowedValues != null) {
ProcessedUnaryTest compileUnaryTests = (ProcessedUnaryTest) FEEL.compileUnaryTests(allowedValues, FEEL.newCompilerContext());
UnaryTestInterpretedExecutableExpression interpreted = compileUnaryTests.getInterpreted();
UnaryTestListNode utln = (UnaryTestListNode) interpreted.getASTNode();
if (utln.getElements().size() != 1) {
verifyUnaryTestsAllEQ(utln, dt);
List<Comparable<?>> discreteValues = getDiscreteValues(utln);
List<Comparable<?>> outputOrder = new ArrayList<>(discreteValues);
Collections.sort((List) discreteValues);
Interval discreteDomainMinMax = new Interval(RangeBoundary.CLOSED, discreteValues.get(0), discreteValues.get(discreteValues.size() - 1), RangeBoundary.CLOSED, 0, jColIdx + 1);
DDTAOutputClause ic = new DDTAOutputClause(discreteDomainMinMax, discreteValues, outputOrder);
ddtaTable.getOutputs().add(ic);
} else if (utln.getElements().size() == 1) {
UnaryTestNode utn0 = (UnaryTestNode) utln.getElements().get(0);
Interval interval = utnToInterval(utn0, infDomain, null, 0, jColIdx + 1);
DDTAOutputClause ic = new DDTAOutputClause(interval);
ddtaTable.getOutputs().add(ic);
} else {
throw new IllegalStateException("inputValues not null but utln: " + utln);
}
} else {
DDTAOutputClause ic = new DDTAOutputClause(infDomain);
ddtaTable.getOutputs().add(ic);
}
}
}
use of org.kie.dmn.model.api.OutputClause 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.OutputClause in project drools by kiegroup.
the class OutputClauseConverter method writeAttributes.
@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
super.writeAttributes(writer, parent);
OutputClause oc = (OutputClause) parent;
if (oc.getName() != null)
writer.addAttribute(NAME, oc.getName());
if (oc.getTypeRef() != null)
writer.addAttribute(TYPE_REF, MarshallingUtils.formatQName(oc.getTypeRef()));
}
use of org.kie.dmn.model.api.OutputClause in project drools by kiegroup.
the class OutputClauseConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
OutputClause oc = (OutputClause) parent;
if (oc.getOutputValues() != null)
writeChildrenNode(writer, context, oc.getOutputValues(), OUTPUT_VALUES);
if (oc.getDefaultOutputEntry() != null)
writeChildrenNode(writer, context, oc.getDefaultOutputEntry(), DEFAULT_OUTPUT_ENTRY);
}
use of org.kie.dmn.model.api.OutputClause in project drools by kiegroup.
the class OutputClauseConverter method assignAttributes.
@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
super.assignAttributes(reader, parent);
OutputClause oc = (OutputClause) parent;
String name = reader.getAttribute(NAME);
String typeRefValue = reader.getAttribute(TYPE_REF);
oc.setName(name);
if (typeRefValue != null)
oc.setTypeRef(MarshallingUtils.parseQNameString(typeRefValue));
}
Aggregations