Custom Function

Hello, I am using Feel Engine Factory with my Spring Boot Application in Java.
https://github.com/camunda/feel-scala/tree/master/feel-engine-factory
There are some built-in functions like “floor”
I need to implement my own function.
I have implemented a function using Java: https://camunda.github.io/feel-scala/function-provider-spi

There is a message in the log:
Engine created. [value-mapper: org.camunda.feel.integration.CamundaValueMapper@6bfbd70f, function-provider: com.a.b.c.config.camunda.CustomJavaFunctionProvider@6ca64178]

This is my DmnEngine:
@Bean
public DmnEngine dmnEngine() {
DefaultDmnEngineConfiguration dmnEngineConfig = (DefaultDmnEngineConfiguration) DmnEngineConfiguration.createDefaultDmnEngineConfiguration();
dmnEngineConfig.setFeelEngineFactory(new CamundaFeelEngineFactory());
dmnEngineConfig.setDefaultOutputEntryExpressionLanguage(“feel”);
return dmnEngineConfig.buildEngine();
}

If I try to evaluate a table with my function, there is an error:
org.camunda.bpm.dmn.feel.impl.FeelException: failed to evaluate expression ‘decr(3)’: no function found with name ‘decr’ and 1 parameters
Can anyone help please?

It uses my CustomJavaFunctionProvider because of
Engine created. [value-mapper: org.camunda.feel.integration.CamundaValueMapper@18b349bc, function-provider: com.a.b.c.config.camunda.CustomJavaFunctionProvider@24015985]

But it never use a resolveFunction method. Why?

@vladislavmungalov, which version of FEEL-Scala do you use?

@Philipp_Ossler I use feel-engine-factory 1.9.0, I use only DMN Engine without Process Engine, because I don’t need BPM.

        <groupId>org.camunda.bpm.extension.feel.scala</groupId>
        <artifactId>feel-engine-factory</artifactId>
        <version>1.9.0</version>

        <groupId>org.camunda.spin</groupId>
        <artifactId>camunda-spin-core</artifactId>
        <version>1.7.4</version>

I’ve fixed it. The topic can be closed.

Nice to hear :+1:

What was the problem?
This could help others who run into the same problem :slight_smile:

@vladislavmungalov Would you be able to share on how you solved this please? I’m facing the same error

@vincentgiraud It’s almost 2 years since that project :slight_smile: but try to set DefaultOutputEntryExpressionLanguage to “feel-scala”:

dmnEngineConfig.setDefaultOutputEntryExpressionLanguage(“feel-scala”);

so your dmn engine should look like:

@Bean
public DmnEngine dmnEngine() {
    DefaultDmnEngineConfiguration dmnEngineConfig = (DefaultDmnEngineConfiguration) DmnEngineConfiguration.createDefaultDmnEngineConfiguration();
    dmnEngineConfig.setFeelEngineFactory(new CamundaFeelEngineFactory());
    dmnEngineConfig.setDefaultOutputEntryExpressionLanguage("feel-scala");
    return dmnEngineConfig.buildEngine();
}

Thanks for your swift reply vladislavmungalov!

1 Like

Hello @vladislavmungalov

Thank you for your feedback.

I did as you mentioned, and I have created a new class CamundaFeelEngineFactory:

package io.zeebe.dmn;
import org.camunda.bpm.dmn.feel.impl.FeelEngine;
import org.camunda.bpm.dmn.feel.impl.FeelEngineFactory;
import org.camunda.bpm.dmn.feel.impl.juel.FeelEngineFactoryImpl;

public class CamundaFeelEngineFactory implements FeelEngineFactory {
    @Override
    public FeelEngine createInstance() {
        FeelEngineFactoryImpl factoryImpl = new FeelEngineFactoryImpl();
        return factoryImpl.createInstance();
    }
}

Afterwards, I ran mvn clean install of the Zeebe DMN Worker and the tests seem to fail:

2021-05-05 10:03:53.387  INFO 13376 --- [           main] io.zeebe.dmn.WorkflowTest                : Started WorkflowTest in 4.813 seconds (JVM running for 37.999)
2021-05-05 10:03:54.590  INFO 13376 --- [ault-executor-0] io.zeebe.client.job.poller               : Activated 1 jobs for worker camunda-dmn-worker and job type DMN
2021-05-05 10:03:54.641  WARN 13376 --- [pool-6-thread-1] io.zeebe.client.job.worker               : Worker camunda-dmn-worker failed to handle job with key 2251799813685258 of type DMN, sending fail command to broker

java.lang.UnsupportedOperationException: FEEL-01016 Simple Expression not supported by FEEL engine
        at org.camunda.bpm.dmn.feel.impl.juel.FeelEngineLogger.simpleExpressionNotSupported(FeelEngineLogger.java:160) ~[camunda-engine-feel-juel-7.14.0.jar:7.14.0]
        at org.camunda.bpm.dmn.feel.impl.juel.FeelEngineImpl.evaluateSimpleExpression(FeelEngineImpl.java:48) ~[camunda-engine-feel-juel-7.14.0.jar:7.14.0]
        at org.camunda.bpm.dmn.engine.impl.evaluation.ExpressionEvaluationHandler.evaluateFeelSimpleExpression(ExpressionEvaluationHandler.java:130) ~[camunda-engine-dmn-7.14.0.jar:7.14.0]
        at org.camunda.bpm.dmn.engine.impl.evaluation.ExpressionEvaluationHandler.evaluateExpression(ExpressionEvaluationHandler.java:59) ~[camunda-engine-dmn-7.14.0.jar:7.14.0]
        at org.camunda.bpm.dmn.engine.impl.evaluation.DecisionTableEvaluationHandler.evaluateInputExpression(DecisionTableEvaluationHandler.java:193) ~[camunda-engine-dmn-7.14.0.jar:7.14.0]
        at org.camunda.bpm.dmn.engine.impl.evaluation.DecisionTableEvaluationHandler.evaluateInput(DecisionTableEvaluationHandler.java:122) ~[camunda-engine-dmn-7.14.0.jar:7.14.0]
        at org.camunda.bpm.dmn.engine.impl.evaluation.DecisionTableEvaluationHandler.evaluateDecisionTable(DecisionTableEvaluationHandler.java:104) ~[camunda-engine-dmn-7.14.0.jar:7.14.0]
        at org.camunda.bpm.dmn.engine.impl.evaluation.DecisionTableEvaluationHandler.evaluate(DecisionTableEvaluationHandler.java:81) ~[camunda-engine-dmn-7.14.0.jar:7.14.0]

Would you have any suggestions regarding this error ?

UPDATE:

I did a mvn clean install -DskipTests, and I still get the error no function found with name 'decr' and 1 parameters

Thank you

@y-io in the AppConfig.java of zeebe-dmn-worker this did the trick:
DefaultDmnEngineConfiguration config =
(DefaultDmnEngineConfiguration)
DmnEngineConfiguration.createDefaultDmnEngineConfiguration();
config.setDefaultOutputEntryExpressionLanguage(“feel-scala”);