Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-5577

Calling static Java method from DMN model (Drools Business Central)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Obsolete
    • Icon: Critical Critical
    • None
    • 7.40.0.Final
    • DMN Editor
    • Hide

      1) In Eclipse (I'm using version 2020-02(4.15.0)), create new Maven project (archetype: groupid: org.apache.maven.archetype, artifactId: maven-archetype-quickstart)

      2) Add new StandardDeviationA class (update package name as required):

       

      package com.samplea.drools.DroolsNewTypes5;
      import java.math.BigDecimal;
      public class StandardDeviationA {
           public static BigDecimal stdev_a(java.lang.Number val) { 
              return new BigDecimal(val.doubleValue() * 2); 
          }
      }
      

       

      3) Right-click on new project, choose Run As -> Maven Install 

      4) Copy location of generated .jar file

      5) In Business Central, go to Artifacts (click cog in the top right hand corner, choose Artifacts icon)

      6) Add new artifact by clicking upload and choosing location of .jar from step 4)

      7) Go to the project in Business Central Space (or create new project).

      8) In the project, click on Settings tab (top). Go to Dependencies tab (left). 

      9) Click "Add from repository" link.

      Add jar as:

              group id: com.samplea.drools 

              artifact ID: DroolsNewTypes5 

              version 0.0.1-SNAPSHOT   

              package whitelist: All   

      Click Save

      10) Go to Assets tab (top). Add new Asset.

      In new asset, add BKM (business knowledge model) element

      11) Double click BKM element to go to details. Configure it as follows:

      function kind: Java (J)

      class: "com.samplea.drools.DroolsNewTypes5.StandardDeviationA"

      method signature: "stdev_a(java.lang.Number)"

       

      Click Save button (top)

      Alerts pane shows the error

       

       

      Show
      1) In Eclipse (I'm using version 2020-02(4.15.0)), create new Maven project (archetype: groupid: org.apache.maven.archetype, artifactId: maven-archetype-quickstart) 2) Add new StandardDeviationA class (update package name as required):   package com.samplea.drools.DroolsNewTypes5; import java.math.BigDecimal; public class StandardDeviationA { public static BigDecimal stdev_a(java.lang. Number val) { return new BigDecimal(val.doubleValue() * 2); } }   3) Right-click on new project, choose Run As -> Maven Install  4) Copy location of generated .jar file 5) In Business Central, go to Artifacts (click cog in the top right hand corner, choose Artifacts icon) 6) Add new artifact by clicking upload and choosing location of .jar from step 4) 7) Go to the project in Business Central Space (or create new project). 8) In the project, click on Settings tab (top). Go to Dependencies tab (left).  9) Click "Add from repository" link. Add jar as:         group id: com.samplea.drools          artifact ID: DroolsNewTypes5          version 0.0.1-SNAPSHOT            package whitelist: All    Click Save 10) Go to Assets tab (top). Add new Asset. In new asset, add BKM (business knowledge model) element 11) Double click BKM element to go to details. Configure it as follows: function kind: Java (J) class: "com.samplea.drools.DroolsNewTypes5.StandardDeviationA" method signature: "stdev_a(java.lang.Number)"   Click Save button (top) Alerts pane shows the error    
    • NEW
    • NEW

      When calling static Java method stdev_a (which I created in a new Java Maven project) from Drools Business Central DMN project/model, I'm getting following error:

       

      DMN: Error compiling Java function 'stdev' on node 'stdev': Error resolving external function as defined by: function(val) external { java: { class: ""com.samplea.drools.DroolsNewTypes5.StandardDeviationA"", method signature: ""stdev_a(java.lang.Number)"" }} (DMN id: _3B4B6CBE-847B-4488-8754-214F506BBB48, Error compiling the referenced FEEL expression)

       

      Also, how to view logs of DMN model when it has build errors? 

        1. Artifacts.PNG
          Artifacts.PNG
          11 kB
        2. Artifacts0.PNG
          Artifacts0.PNG
          12 kB
        3. bpms_dmn-java.zip
          8 kB
        4. dependencies.PNG
          dependencies.PNG
          17 kB
        5. DroolsNewTypes5-0.0.1-SNAPSHOT.jar
          4 kB
        6. standard-deviation-1.0.0-SNAPSHOT.jar
          2 kB
        7. stdev 0.PNG
          stdev 0.PNG
          19 kB
        8. stdev 1.PNG
          stdev 1.PNG
          30 kB

            karreiro_ Guilherme Gomes (Inactive)
            tmandekic K M (Inactive)
            Barbora Kapustova Barbora Kapustova
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: