Hi everyone,
I’m trying to find some help with custom functions for DMN engine. So, I’m using the flowable-spring-boot-starter-rest and I’m trying to execute a DMN rule with a custom function.
I created my custom function NextBusinessDay:
public class NextBusinessDay extends AbstractFlowableFunctionDelegate {
public NextBusinessDay() {
}
@Override
public String prefix() {
return "dates";
}
@Override
public String localName() {
return "nextBusinessDay";
}
@Override
public Class<?> functionClass() {
return DateUtils.class;
}
@Override
public Method functionMethod() {
return getSingleObjectParameterMethod("nextBusinessDay");
}
}
This is the static method that I aims to be called:
public class DateUtils {
public static Date nextBusinessDay(Date d) {
return org.apache.commons.lang3.time.DateUtils.addDays(d, 5);
}
}
Here is my DMN engine setup where I have already deployed a DMN table and added my custom function NextBusinessDay.
@Configuration
public class DmnEngineSetup {
@Autowired
private DmnEngine engine;
private URL url = getClass().getResource("/dmn");
private List<FlowableFunctionDelegate> flowableFunctionDelegateList =
Arrays.asList(new NextBusinessDay());
@PostConstruct
public void deploy() throws URISyntaxException, IOException {
engine.getDmnEngineConfiguration()
.setCustomFlowableFunctionDelegates(flowableFunctionDelegateList);
Path path = Paths.get(url.toURI());
Files.list(path).forEach(p -> {
engine.getDmnRepositoryService()
.createDeployment()
.name("test")
.addClasspathResource("dmn/" + p.getFileName().toString())
.enableDuplicateFiltering()
.deploy();
});
}
}
Finally, I have my DMN definition using my custom function:
<definitions xmlns="http://www.omg.org/spec/DMN/20180521/MODEL/" id="definition_afbe03b6-6604-11eb-bbcf-0242ac110002" name="Next Business Day" namespace="http://www.flowable.org/dmn">
<decision id="nextBusinessDay" name="Next Business Day">
<decisionTable id="decisionTable_afbe03b6-6604-11eb-bbcf-0242ac110002" hitPolicy="FIRST">
<input label="Date">
<inputExpression id="inputExpression_1" typeRef="date">
<text>inputVar</text>
</inputExpression>
</input>
<output id="outputExpression_2" label="Next Business Day" name="nextBusinessDay" typeRef="date"></output>
<rule>
<inputEntry id="inputEntry_1_1">
<text><![CDATA[-]]></text>
</inputEntry>
<outputEntry id="outputEntry_2_1">
<text><![CDATA[dates:nextBusinessDay(inputVar)]]></text>
</outputEntry>
</rule>
</decisionTable>
</decision>
</definitions>
Thus when I try to execute the rule I get an error that says: “Could not resolve function ‘dates:nextBusinessDay’”
Thanks,
Bruno Alves