How to compose input object for "processAPI.executeUserTask" method

1
+1
-1

Hi to All,
I'm having difficulties in consuming method processAPI.executeUserTask(long userTaskInstanceId, Map<String,Serializable> inputs) via bonita java API.

I just can't format Serializable object/value for Map<String,Serializable> in a right way. I always get exception "cannot be assigned to COMPLEX type"

org.bonitasoft.engine.bpm.contract.ContractViolationException: USERNAME=walter.bates | Error while validating expected inputs: [[{attributeName: "aaaaaaaa", attributeValue: "bbbbbbbbb"}] cannot be assigned to COMPLEX type]

I have tried various JSON forms, but always i get the same message. Contract(input) is expecting object lookup with attributes: attributeName, attributeValue.

I would be grateful if someone can post link to example of using executeUserTask method or how to invoke it properly, or even better to post here short code sample.

Thanks,
Marijan

Comments

Submitted by Dibyajit.Roy on Tue, 12/03/2019 - 19:08

any luck.
i am stuck at the same place

3 answers

1
+1
-1
This one is the BEST answer!

Hello,

Your input is a COMPLEX, you have to pass a MAP

here the tip:

in a browser, click on F12., access the Network part

Now, fulfill your form and execute the task: you will see a URL, with the PAYLOAD to pass. This is the JSON you have to fulfill.

In your case, Bonita Contract expect something like

{ "aaaaaaaa" : {

"SubAttribut" : "1232",

"Name":"Bob"}

}

Hope this help,

Comments

Submitted by Dibyajit.Roy on Sat, 01/04/2020 - 19:43

Hello Pierre

Thanks for the example. I am able to solve the issue. I can pass the MAP and complete the task.

I am facing a new issue. To complete the task, I have to create a Session (API Session) by passing username and password.
But, for everyday scenarios, i will have normal users perform this task.I do not have user password saved anywhere.
Is there a way to to pass API session from Form to Script ?
Can we execute the same executeUserTask without session or credentials ?

thanks

1
+1
-1

Hello,

Nice to see that you solved your issue! Do not hesitate to mark the question as resolved, that's help other users who search for the same question.

How do you want to execute the task? I don't get it.

To execute a task, you must be connected. Multiple reasons for that: security first, only users allowed to execute the task can do it. Traceability then: to know who executed the tasks.

==> for everyday scenarios, I will have normal users perform this task.I do not have a user password saved anywhere. Is there a way to pass API session from Form to Script?

Could you explain more? If the user can access the form, then he is connected, he has a Cookie with the API Session and then the REST API call will work.

If the user call a REST API Extension, then on the REST Groovy Script, you have a APIAccessor to get the ProcessAPI. So, technically, you have an API Extension.

Can we execute the same executeUserTask without session or credentials?

==> If you execute the JAVA part on the Bonita Server (in a REST API Extension, in a Groovy connector) then you are connected. The Groovy Connector is executed with a technical user. You don't need to connect

==> If you execute the JAVA part out the Bonita Server, then first you have to use the Login API to connect to the server. Then you need a login/password.

Hope this help,

Comments

Submitted by Dibyajit.Roy on Mon, 01/06/2020 - 10:14

Hello Pierre

Thanks for your answer.
I have a page where i show all the tasks assigned to user. Then user can choose a check box to return task Id of those particular tasks. I have a process with task Id as contract. Hence Process is started with contract inputs.
Now I have a groovy script connector where i have used the below script.

IdentityAPI identity = apiAccessor.getIdentityAPI();
User user = identity.getUserByUserName("walter.bates");

LoginAPI loginAPI = TenantAPIAccessor.getLoginAPI();
APISession session = loginAPI.login("walter.bates", "bpm");

ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(session);

def date= new Date();
def docs = [];

Map m = new HashMap<>();
m.put('taskcomments','Test');
m.put('taskStartdate',date);
m.put('tasksubreqid',"14-2");
m.put('isSlaMet','Yes');
m.put('attachedDocs',docs);
m.put('taskapprover','walter.bates');

final List pendingTasks = processAPI.getPendingHumanTaskInstances(session.getId(),0,0,ActivityInstanceCriterion.PRIORITY_ASC);
// processAPI.executeFlowNode(user.getId(),320054);
processAPI.executeUserTask(320054, m)

1 ) So my difficulty is how do i get the user's session passed from page to Groovy connector.

2) If I use technical user credentials, then will the task show as completed by Install and not username .

3) Any other way i can achieve this ?

thanks a lot for your help.

Submitted by Pierre-yves Monnet on Fri, 01/10/2020 - 10:24

Hello,

A Groovy connector is executed by the Bonita Engine. You must not try to log and to execute anythink as a user.

1/ security reason: to log, you must have the user password. You plan to hardcode all users password in the connector ?

2/ Connector is executed as a System user. It's against the spirit of the product to do that.

If you want to search tasks for a users, use the searchAssignedAndPendingHumanTasksFor() API

searchAssignedAndPendingHumanTasksFor(long rootProcessDefinitionId, long userId, SearchOptions searchOptions)

Hope this help

Submitted by Dibyajit.Roy on Mon, 01/13/2020 - 10:36

Thank you.

I solved my issue. Final working code is below.

import org.bonitasoft.engine.api.LoginAPI;
import org.bonitasoft.engine.bpm.connector.ConnectorInstance;
import org.bonitasoft.engine.bpm.connector.ConnectorInstancesSearchDescriptor;
import org.bonitasoft.engine.bpm.connector.ConnectorState;
import org.bonitasoft.engine.bpm.connector.ConnectorStateReset;
import org.bonitasoft.engine.search.Order;
import org.bonitasoft.engine.search.SearchOptions;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.search.SearchResult;
import org.bonitasoft.engine.session.APISession;
import com.bonitasoft.engine.api.LogAPI;
import com.bonitasoft.engine.api.ProcessAPI;
import com.bonitasoft.engine.api.TenantAPIAccessor;
import com.bonitasoft.engine.log.Log;
import com.bonitasoft.engine.log.LogSearchDescriptor;

Map m = new HashMap<>();

apiAccessor.processAPI.executeUserTask(760243, m)

1
0
-1
Notifications