As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
activiti:candidateUsers="accountancyUser"
List<Task> myTasks =<br> processEngine.getTaskService().createTaskQuery().processDefinitionId(processInstance.getId())<br> .taskCandidateUser("accountancyUser").list();
<definitions id="definitions"<br> targetNamespace="<a href="http://activiti.org/bpmn20" rel="nofollow noopener noreferrer">http://activiti.org/bpmn20</a>"<br> xmlns:activiti="<a href="http://activiti.org/bpmn" rel="nofollow noopener noreferrer">http://activiti.org/bpmn</a>"<br> xmlns="<a href="http://www.omg.org/spec/BPMN/20100524/MODEL" rel="nofollow noopener noreferrer">http://www.omg.org/spec/BPMN/20100524/MODEL</a>"><br><br> <process id="assigningRoles"><br><br> <startEvent id="begin"/><br><br> <sequenceFlow id="flow1" sourceRef="begin" targetRef="createReport"/><br><br> <userTask id="createReport" name="create the report" activiti:candidateUsers="accountancyUser"/><br><br> <sequenceFlow id="flow2" sourceRef="createReport" targetRef="verifyReport"/><br><br> <userTask id="verifyReport" name="verify the report" activiti:candidateUsers="accountancyUser"/><br><br> <sequenceFlow id="flow3" sourceRef="verifyReport" targetRef="end"/><br><br> <endEvent id="end"/><br><br> </process><br><br></definitions>
<br> // create a test user in group ROLE_EDIT<br> User accountancyUser = identityService.newUser("accountancyUser");<br> Group accountancyGroup = identityService.newGroup("ROLE_EDIT");<br> identityService.saveGroup(accountancyGroup);<br> identityService.saveUser(accountancyUser);<br> identityService.createMembership(accountancyUser.getId(),<br> accountancyGroup.getId());<br><br> List<Group> groups = identityService.createGroupQuery()<br> .groupId("ROLE_EDIT").list();<br> assertEquals(1, groups.size());<br><br> List<User> users = identityService.createUserQuery()<br> .memberOfGroup("ROLE_EDIT").list();<br> assertEquals(1, users.size());<br><br> accountancyUser = users.get(0);<br> assertEquals("accountancyUser", accountancyUser.getId());<br><br> // start the process<br> ProcessInstance processInstance = runtimeService<br> .startProcessInstanceByKey("assigningRoles");<br><br> // "accountancyUser" should have one task after the process instance was<br> // created<br> List<Task> myTasks = processEngine.getTaskService().createTaskQuery()<br> .processDefinitionId(processInstance.getId())<br> .taskCandidateUser("accountancyUser").list();<br> Assert.assertNotNull(myTasks);<br>// here the test fails:<br> Assert.assertEquals(1, myTasks.size());<br><br> // now see if he's involved user on any task of the the process instance<br> Assert.assertTrue(processEngine.getTaskService().createTaskQuery()<br> .processDefinitionId(processInstance.getId())<br> .taskInvolvedUser("accountancyUser").list().size() == 0);<br><br> // now add myself to the task as candidate user<br> processEngine.getTaskService().addCandidateUser(myTasks.get(0).getId(),<br> "accountancyUser");<br><br> // and now all of a sudden i'm involved user on the task<br> Assert.assertTrue(processEngine.getTaskService().createTaskQuery()<br> .processDefinitionId(processInstance.getId())<br> .taskInvolvedUser("accountancyUser").list().size() == 1);<br> }<br>
processDefinitionId(processInstance.getId())
// "accountancyUser" should have one task after the process instance was<br> // created<br> List<Task> myTasks = processEngine.getTaskService().createTaskQuery()<br> .processDefinitionId(processInstance.getId())<br> .taskCandidateUser("accountancyUser").list();
processInstance.getProcessDefinitionId()