REST API extension - Groovy script - Unable to call processAPI.searchHumanTaskInstances()

Hi all,

I am writing a REST API extension to search and return current bpm data.

In current step, I use function [searchProcessInstances] to get all of current cases data, and then for each of it, use [searchHumanTaskInstances] get human task data.
The code is as below:

def processAPI = context.apiClient.processAPI
def identityAPI = context.apiClient.getIdentityAPI()

SearchOptionsBuilder processInstanceSearchOptionsBuilder = new SearchOptionsBuilder(0, 9999)
SearchOptions processInstanceSearchOptions = processInstanceSearchOptionsBuilder.done()
LOGGER.info("    - processInstanceSearchOptions(" + processInstanceSearchOptions.toString() + "): " + new JsonBuilder(processInstanceSearchOptions).toPrettyString())
def processInstanceResult = processAPI.searchProcessInstances(processInstanceSearchOptions)
LOGGER.info("searchResult: " + processInstanceResult.count)
int i = 1
for(def pi in processInstanceResult.result){
    LOGGER.info("    Process Instance " + i.toString())
    LOGGER.info("    - id: " + pi.id)
    LOGGER.info("    - name: " + pi.name)
    LOGGER.info("    - processDefinitionId: " + pi.processDefinitionId)
    LOGGER.info("    - rootProcessInstanceId: " + pi.rootProcessInstanceId)
    
    SearchOptionsBuilder humanTaskSearchOptionsBuilder = new SearchOptionsBuilder(0, 9999).filter(HumanTaskInstanceSearchDescriptor.ROOT_PROCESS_INSTANCE_ID, pi.rootProcessInstanceId)
    SearchOptions humanTaskSearchOptions = humanTaskSearchOptionsBuilder.done()
    LOGGER.info("    - humanTaskOptions(" + humanTaskSearchOptions.toString() + "): " + new JsonBuilder(humanTaskSearchOptions).toPrettyString())
    def humanTaskResult = processAPI.searchHumanTaskInstances​(humanTaskSearchOptions)
    LOGGER.info("    - humanTask: " + new JsonBuilder(humanTaskResult.result).toPrettyString())

    i+=1
}

For some reason, [searchProcessInstances] run normally, but [searchHumanTaskInstances​] return error below:

26-Oct-2021 13:40:17.719 SEVERE [http-nio-59788-exec-4] org.bonitasoft.console.common.server.page.RestApiRenderer.renderResponse Error when executing rest api extension call to apiExtension|GET|summaryByCase
    groovy.lang.MissingMethodException: No signature of method: com.sun.proxy.$Proxy122.searchHumanTaskInstances​() is applicable for argument types: (org.bonitasoft.engine.search.impl.SearchOptionsImpl) values: [org.bonitasoft.engine.search.impl.SearchOptionsImpl@f8086bbf]
Possible solutions: searchHumanTaskInstances(org.bonitasoft.engine.search.SearchOptions)

 

I am using Community version of BonitaSoft. Is this the reason these function is not supported?

Thanks in advance,

EDIT: I also call 2 function to get user and user membership data from StartBy field, after block the above error code.

def user = identityAPI.getUser(processInstance.startedBy)
def userMemberships​ = identityAPI.getUserMemberships​(processInstance.startedBy, startIndex, maxResults, UserMembershipCriterion.GROUP_NAME_ASC)

Function [getUser] run normally, but [getUserMemberships​] throw error below:

26-Oct-2021 16:52:15.505 SEVERE [http-nio-59788-exec-10] org.bonitasoft.console.common.server.page.RestApiRenderer.renderResponse Error when executing rest api extension call to apiExtension|GET|summaryByCase
    groovy.lang.MissingMethodException: No signature of method: com.sun.proxy.$Proxy121.getUserMemberships​() is applicable for argument types: (java.lang.Long, java.lang.Integer, java.lang.Integer, org.bonitasoft.engine.identity.UserMembershipCriterion) values: [878, 0, 2147483647, GROUP_NAME_ASC]
Possible solutions: getUserMemberships(long, int, int, org.bonitasoft.engine.identity.UserMembershipCriterion), getUserMembership(long)

For some unknown reason, I am able to make it work now.

All I did was create a Groovy class inside Bonita IDE, create a function and copy the above code into it, run the function, and now and REST API extension no longer throw exception.

EDIT: Sorry, my mistake.
The error is still there, what I successed to do is using get*** function, like processAPI.getProcessDefinition().
search*** function still not work.

Final edit: The whole cause of this issue is kind of stupid. I copy the functions' name from Bonita JavaDoc to my code, and some of them have an invisible character right after the function name. When I pasted them to me code and run, the exception is thrown. Because it is invisible, I have no idea that the character was there. Only after my team member open the file on his text editor that show every characters/symbols in the file (include Enter , Tab, etc), we discover the character. The reason I manage to run the code as in the beginning of this reply is because I copy the function name into Bonita IDE, not the whole code line, run there, then copy whole code line back to the REST API Extension code file.

 

Hello
Could you write or publish an article or blog and just write the steps to follow to create a custom REST API.
Actually an easy step by step guide would help the community .

Thanks & regards
 

Hi,

Are you executing your rest api extension using the Studio environment ?
What version of the Studio are you using ?
Can you share your project on a public GitHub repo ?

I have found the cause, and it is kind of stupid.

Please check my edit in the above comment.

Ouch, those hurts.
Glad you find it !