use of org.kie.dmn.core.ast.DecisionServiceNodeImpl in project drools by kiegroup.
the class DMNCompilerImpl method processDrgElements.
private void processDrgElements(DMNCompilerContext ctx, DMNModelImpl model, Definitions dmndefs) {
for (DRGElement e : dmndefs.getDrgElement()) {
boolean foundIt = false;
for (DRGElementCompiler dc : drgCompilers) {
if (dc.accept(e)) {
foundIt = true;
dc.compileNode(e, this, model);
continue;
}
}
if (!foundIt) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, e, model, null, null, Msg.UNSUPPORTED_ELEMENT, e.getClass().getSimpleName(), e.getId());
}
}
// in DMN v1.1 the DecisionService is not on the DRGElement but as an extension
if (dmndefs.getExtensionElements() != null) {
List<DecisionServices> decisionServices = dmndefs.getExtensionElements().getAny().stream().filter(DecisionServices.class::isInstance).map(DecisionServices.class::cast).collect(Collectors.toList());
for (DecisionServices dss : decisionServices) {
for (DecisionService ds : dss.getDecisionService()) {
// compatibility with DMN v1.1, create Decision Service's variable:
if (ds.getVariable() == null) {
InformationItem variable = new TInformationItem();
variable.setId(UUID.randomUUID().toString());
variable.setName(ds.getName());
variable.setParent(ds);
// the introduction of an on-the-fly ItemDefinition has been removed. The variable type will be evaluated as feel:any, or in v1.2 will receive the (user-defined, explicit) ItemDefinition type.
ds.setVariable(variable);
}
// continuing with normal compilation of Decision Service:
boolean foundIt = false;
for (DRGElementCompiler dc : drgCompilers) {
if (dc.accept(ds)) {
foundIt = true;
dc.compileNode(ds, this, model);
continue;
}
}
}
}
}
for (DecisionServiceNode ds : model.getDecisionServices()) {
DecisionServiceNodeImpl dsi = (DecisionServiceNodeImpl) ds;
dsi.addModelImportAliases(model.getImportAliasesForNS());
for (DRGElementCompiler dc : drgCompilers) {
if (dsi.getEvaluator() == null && dc.accept(dsi)) {
// will compile in fact all DS belonging to this model (not the imported ones).
dc.compileEvaluator(dsi, this, ctx, model);
}
}
}
for (BusinessKnowledgeModelNode bkm : model.getBusinessKnowledgeModels()) {
BusinessKnowledgeModelNodeImpl bkmi = (BusinessKnowledgeModelNodeImpl) bkm;
bkmi.addModelImportAliases(model.getImportAliasesForNS());
for (DRGElementCompiler dc : drgCompilers) {
if (bkmi.getEvaluator() == null && dc.accept(bkm)) {
dc.compileEvaluator(bkm, this, ctx, model);
}
}
}
for (DecisionNode d : model.getDecisions()) {
DecisionNodeImpl di = (DecisionNodeImpl) d;
di.addModelImportAliases(model.getImportAliasesForNS());
for (DRGElementCompiler dc : drgCompilers) {
if (di.getEvaluator() == null && dc.accept(d)) {
dc.compileEvaluator(d, this, ctx, model);
}
}
}
for (AfterProcessDrgElements callback : afterDRGcallbacks) {
logger.debug("About to invoke callback: {}", callback);
callback.callback(this, ctx, model);
}
detectCycles(model);
}
use of org.kie.dmn.core.ast.DecisionServiceNodeImpl in project drools by kiegroup.
the class DMNRuntimeImpl method evaluateDecisionService.
private void evaluateDecisionService(DMNContext context, DMNResultImpl result, DecisionServiceNode d, boolean typeCheck) {
DecisionServiceNodeImpl ds = (DecisionServiceNodeImpl) d;
if (isNodeValueDefined(result, ds, ds)) {
// already resolved
return;
}
// Note: a Decision Service is expected to always have an evaluator, it does not depend on an xml expression, it is done always by the compiler.
try {
// a Decision Service when is evaluated as a function does not require any dependency check, as they will be passed as params.
EvaluatorResult er = ds.getEvaluator().evaluate(this, result);
if (er.getResultType() == EvaluatorResult.ResultType.SUCCESS) {
FEELFunction resultFn = (FEELFunction) er.getResult();
result.getContext().set(ds.getName(), resultFn);
}
} catch (Throwable t) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, ds.getSource(), result, t, null, Msg.ERROR_EVAL_DS_NODE, getIdentifier(ds), t.getMessage());
}
}
use of org.kie.dmn.core.ast.DecisionServiceNodeImpl in project drools by kiegroup.
the class DMNEventUtils method extractDSParameters.
public static Map<String, Object> extractDSParameters(BeforeEvaluateDecisionServiceEvent event) {
Map<String, Object> results = new LinkedHashMap<String, Object>();
DecisionServiceNodeImpl dsi = (DecisionServiceNodeImpl) event.getDecisionService();
Map<String, DMNNode> params = dsi.getInputParameters();
for (Entry<String, DMNNode> entry : params.entrySet()) {
String name = entry.getKey();
Object value = event.getResult().getContext().get(name);
results.put(name, value);
}
return results;
}
Aggregations