Reasantly i have a lot of requests to add user to group witch is also requaered to add him to active buisness-processes.
For a while i used some uneffective methods - just kill ProcInstances and restart them in stoped point (there wa only few of them so it wasnt a big problem). Since my procStarters find users for procInstances from sec$Role/Group - new user was assigned for tasks.
And right now i don’t see it like a solid solution since requests appears a lot more frequently.
Any idea how to write a method with will be assign user to a procRole and active tasks?
Adding new Actor to process - pretty common task but i still have no idea how to check if active task is suitable for selected procRole
/* num - orderNum of procRole for our new user */
for (/*some loop wth procInstances: (ProcInstance)proc */) {
if (proc != null) {
ProcDefinition procDefinition = proc.getProcDefinition();
ProcRole role = procDefinition.getProcRoles().get(num);
ProcActor actor = metadata.create(ProcActor.class);
actor.setUser(user);
actor.setOrder(num);
actor.setProcInstance(proc);
actor.setProcRole(procDefinition.getProcRoles().get(num));
actor = dataManager.commit(actor);
for (ProcTask task : proc.getProcTasks()) {
if ((task.getCancelled() == null || !task.getCancelled())
&& task.getEndDate() == null
&& task.getClaimDate() == null
&& task.getProcRole() == null) {
/*
* Here we have potential task for our user, but i still have no idea how check that selected Role is correct for particular procTask
*/
Set<User> users = task.getCandidateUsers();
users.add(user);
task.setCandidateUsers(users);
dataManager.commit(task);
}
}
}
}
}
com.haulmont.bpm.core.ExtensionElementsManager.getTaskProcRole(String actProcessDefinitionId, String actTaskDefinitionKey) should return a role name for the task.
As for assigning new users, in addition to creating a new ProcActor instance, you’ll probably also need to update the assignee using Activiti framework API org.activiti.engine.TaskService#setAssignee or org.activiti.engine.TaskService#addCandidateUser
Thank you! com.haulmont.bpm.core.ExtensionElementsManager.getTaskProcRole(String actProcessDefinitionId, String actTaskDefinitionKey) exactly what i am looking for. It would be helpefull if this API link will appear in bpm-addon documentation
Btw. Assign user to candidate list also works fine from code below (maybe it is a feature as far as we already have two methods for adding candidate users)