How to claim a user task and assign to a user

cancel
Showing results for 
Search instead for 
Did you mean: 
bhanuy
Member II

How to claim a user task and assign to a user

I am developing spring boot app with Activiti 7. when I submit a request,processInstace start the BPMN flow, trying to assign a task to user and then user can process the request. How to assign a task to a user?

Here is my sample code:

Configuration class:

@override
@Autowired
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(myUserDetailsService());
}

@bean
public UserDetailsService myUserDetailsService() {
InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager();

String[][] usersGroupsAndRoles = {
{"user1", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"},
{"other", "password", "ROLE_ACTIVITI_USER", "GROUP_otherTeam"},
{"admin", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"},
};

for (String[] user : usersGroupsAndRoles) {
List<String> authoritiesStrings = Arrays.asList(Arrays.copyOfRange(user, 2, user.length));
logger.info("> Registering new user: " + user[0] + " with the following Authorities[" + authoritiesStrings + "]");
inMemoryUserDetailsManager.createUser(new User(user[0], passwordEncoder().encode(user[1]),
authoritiesStrings.stream().map(s -> new SimpleGrantedAuthority(s)).collect(Collectors.toList())));
}
return inMemoryUserDetailsManager;
}

service class:

public ProcessInstance startProcessInstance(AccessRequest request) {
ProcessInstance instance= processRuntime.start(ProcessPayloadBuilder
.start()
.withProcessDefinitionKey(API_ACCESS_PROCESS)
.withVariable(VAR_ACCESS_REQUEST,
request)
.build());

List<org.activiti.engine.task.Task> tasks = taskService.createTaskQuery().processInstanceId(instance.getId()).list();
return instance;
}

Model:

public class AccessRequest {

private String formId;

private String formName;

public String getFormId() {
return formId;
}

public void setFormId(String formId) {
this.formId = formId;
}

public String getFormName() {
return formName;
}

public void setFormName(String formName) {
this.formName = formName;
}

Here is my user task in xml

<userTask id="UserTask_1" activiti:exclusive="true" activiti:assignee="" name="User Task 1">
<incoming>SequenceFlow_3</incoming>
<outgoing>SequenceFlow_5</outgoing>
</userTask>

how to assign the assignee name here?

I am trying to call from postman and run "StartProcessInstance" then claim the task and complete the task.