cancel
Showing results for 
Search instead for 
Did you mean: 

Assigning task to users group based on condition in enterprise Activiti

rahiakela
Confirmed Champ
Confirmed Champ

I have tree users group and want to assign task to the users group based on complexity value.These are my group users:

1-expert_users

2-senior_users

3-junior_users

1-If complexity value is "High" then the task must be assigned to expert_users group

2-If complexity value is "Medium" then the task must be assigned to senior_users group

3-If complexity value is "Low" then the task must be assigned to junior_users group

I have created task listener as follow:

And I have used expression  as follow:

I have set an variable as global scope as follow:

After done above implementation, I am getting below error:

Please let me know what I am doing wrong here.

Thanks

4 REPLIES 4

rahiakela
Confirmed Champ
Confirmed Champ

After I have modified task listener implementation, the error has gone but dynamic group assignment still not working.

rahiakela
Confirmed Champ
Confirmed Champ

This is done by using this following implementation:

The GroupService is part of which library?

amruta_w
Star Collaborator
Star Collaborator

Hi, 

Please find the attached app.

You can write your task listener as like below, hope it solves your problem.

package com.activiti.extension.bean;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.util.json.JSONArray;
import org.activiti.engine.impl.util.json.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import sun.misc.BASE64Encoder;

public class test implements TaskListener {
RestTemplate restTemplate = new RestTemplate();
String url = "http://localhost:8082/activiti-app";

@Override
public void notify(DelegateTask task) {
// TODO Auto-generated method stub
DelegateExecution execution = task.getExecution();
String cmplx=(String) execution.getVariable("complexity");
System.out.println("complexity="+cmplx);
String groupName="";
String groupId="";
HttpEntity<String> requestEntity = new HttpEntity<String>("", getHeadersForAPS());
if(cmplx.toLowerCase().equals("high")) {
groupName="high";
ResponseEntity<String> groupData = restTemplate.exchange(url+"/api/enterprise/groups?filter="+groupName, HttpMethod.GET, requestEntity, String.class);
System.out.println("groupData="+groupData.getBody());
JSONObject getSubGroupDataJson = new JSONObject(groupData.getBody());
JSONArray dataArray= getSubGroupDataJson.getJSONArray("data");
groupId = dataArray.getJSONObject(0).getString("id");


}
else if(cmplx.toLowerCase().equals("medium")) {
groupName="medium";
ResponseEntity<String> groupData = restTemplate.exchange(url+"/api/enterprise/groups?filter="+groupName, HttpMethod.GET, requestEntity, String.class);
System.out.println("groupData="+groupData.getBody());
JSONObject getSubGroupDataJson = new JSONObject(groupData.getBody());
JSONArray dataArray= getSubGroupDataJson.getJSONArray("data");
groupId = dataArray.getJSONObject(0).getString("id");
}
else {
groupName="low";
ResponseEntity<String> groupData = restTemplate.exchange(url+"/api/enterprise/groups?filter="+groupName, HttpMethod.GET, requestEntity, String.class);
System.out.println("groupData="+groupData.getBody());
JSONObject getSubGroupDataJson = new JSONObject(groupData.getBody());
JSONArray dataArray= getSubGroupDataJson.getJSONArray("data");
groupId = dataArray.getJSONObject(0).getString("id");
}
System.out.println("groupId="+groupId);
task.addCandidateGroup(groupId);
System.out.println("ggg="+task.getCandidates());
}

public MultiValueMap<String, String> getHeadersForAPS()
{
String alfrescoUserName = "admin@app.activiti.com";
String alfrescoPassword = "admin";
String authString = alfrescoUserName + ":" + alfrescoPassword;
String authStringEnc = new BASE64Encoder().encode(authString.getBytes());
MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
headers.add("Accept", "application/json");
headers.add("Content-Type", MediaType.APPLICATION_JSON.toString());
headers.add("Authorization", "Basic " + authStringEnc);
return headers;
}

}

Regards

Amruta Wandakar