use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class DelegateTaskTestTaskListener method notify.
public void notify(DelegateTask delegateTask) {
Set<IdentityLink> candidates = delegateTask.getCandidates();
Set<String> candidateUsers = new HashSet<String>();
Set<String> candidateGroups = new HashSet<String>();
for (IdentityLink candidate : candidates) {
if (candidate.getUserId() != null) {
candidateUsers.add(candidate.getUserId());
} else if (candidate.getGroupId() != null) {
candidateGroups.add(candidate.getGroupId());
}
}
delegateTask.setVariable(VARNAME_CANDIDATE_USERS, candidateUsers);
delegateTask.setVariable(VARNAME_CANDIDATE_GROUPS, candidateGroups);
}
use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class ProcessInstanceIdentityLinksTest method testCustomLinkGroupLink.
@Deployment(resources = "org/activiti/engine/test/api/runtime/IdentityLinksProcess.bpmn20.xml")
public void testCustomLinkGroupLink() {
runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
String processInstanceId = runtimeService.createProcessInstanceQuery().singleResult().getId();
runtimeService.addGroupIdentityLink(processInstanceId, "muppets", "playing");
List<IdentityLink> identityLinks = runtimeService.getIdentityLinksForProcessInstance(processInstanceId);
IdentityLink identityLink = identityLinks.get(0);
assertEquals("muppets", identityLink.getGroupId());
assertNull("kermit", identityLink.getUserId());
assertEquals("playing", identityLink.getType());
assertEquals(processInstanceId, identityLink.getProcessInstanceId());
assertEquals(1, identityLinks.size());
runtimeService.deleteGroupIdentityLink(processInstanceId, "muppets", "playing");
assertEquals(0, runtimeService.getIdentityLinksForProcessInstance(processInstanceId).size());
}
use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class ProcessDefinitionIdentityLinksResourceTest method testAddCandidateStarterToProcessDefinition.
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testAddCandidateStarterToProcessDefinition() throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
// Create user candidate
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("user", "kermit");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINKS_COLLECTION, processDefinition.getId()));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("kermit", responseNode.get("user").textValue());
assertEquals("candidate", responseNode.get("type").textValue());
assertTrue(responseNode.get("group").isNull());
assertTrue(responseNode.get("url").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINK, processDefinition.getId(), "users", "kermit")));
List<IdentityLink> createdLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());
assertEquals(1, createdLinks.size());
assertEquals("kermit", createdLinks.get(0).getUserId());
assertEquals("candidate", createdLinks.get(0).getType());
repositoryService.deleteCandidateStarterUser(processDefinition.getId(), "kermit");
// Create group candidate
requestNode = objectMapper.createObjectNode();
requestNode.put("group", "admin");
httpPost.setEntity(new StringEntity(requestNode.toString()));
response = executeRequest(httpPost, HttpStatus.SC_CREATED);
responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("admin", responseNode.get("group").textValue());
assertEquals("candidate", responseNode.get("type").textValue());
assertTrue(responseNode.get("user").isNull());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINK, processDefinition.getId(), "groups", "admin")));
createdLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());
assertEquals(1, createdLinks.size());
assertEquals("admin", createdLinks.get(0).getGroupId());
assertEquals("candidate", createdLinks.get(0).getType());
repositoryService.deleteCandidateStarterUser(processDefinition.getId(), "admin");
}
use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class DynamicUserTaskTest method testChangeCandidateGroups.
@Deployment(resources = { "org/activiti/engine/test/bpmn/usertask/DynamicUserTaskTest.basictask.bpmn20.xml" })
public void testChangeCandidateGroups() {
// first test without changing the form key
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
String processDefinitionId = processInstance.getProcessDefinitionId();
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
List<IdentityLink> taskIdentityLinks = taskService.getIdentityLinksForTask(task.getId());
boolean candidateGroupTestFound = false;
for (IdentityLink identityLink : taskIdentityLinks) {
if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getGroupId() != null && identityLink.getUserId() == null) {
if ("test".equals(identityLink.getGroupId())) {
candidateGroupTestFound = true;
}
}
}
assertFalse(candidateGroupTestFound);
taskService.complete(task.getId());
assertProcessEnded(processInstance.getId());
// now test with changing the form key
ObjectNode infoNode = dynamicBpmnService.changeUserTaskCandidateGroup("task1", "test", true);
dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskIdentityLinks = taskService.getIdentityLinksForTask(task.getId());
candidateGroupTestFound = false;
for (IdentityLink identityLink : taskIdentityLinks) {
if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getGroupId() != null && identityLink.getUserId() == null) {
if ("test".equals(identityLink.getGroupId())) {
candidateGroupTestFound = true;
}
}
}
assertTrue(candidateGroupTestFound);
taskService.complete(task.getId());
infoNode = dynamicBpmnService.getProcessDefinitionInfo(processDefinitionId);
dynamicBpmnService.changeUserTaskCandidateGroup("task1", "test2", false, infoNode);
dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskIdentityLinks = taskService.getIdentityLinksForTask(task.getId());
candidateGroupTestFound = false;
boolean candidateGroupTest2Found = false;
for (IdentityLink identityLink : taskIdentityLinks) {
if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getGroupId() != null && identityLink.getUserId() == null) {
if ("test".equals(identityLink.getGroupId())) {
candidateGroupTestFound = true;
} else if ("test2".equals(identityLink.getGroupId())) {
candidateGroupTest2Found = true;
}
}
}
assertTrue(candidateGroupTestFound);
assertTrue(candidateGroupTest2Found);
taskService.complete(task.getId());
assertProcessEnded(processInstance.getId());
}
use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class DynamicUserTaskTest method testChangeCandidateUsers.
@Deployment(resources = { "org/activiti/engine/test/bpmn/usertask/DynamicUserTaskTest.basictask.bpmn20.xml" })
public void testChangeCandidateUsers() {
// first test without changing the form key
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
String processDefinitionId = processInstance.getProcessDefinitionId();
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
List<IdentityLink> taskIdentityLinks = taskService.getIdentityLinksForTask(task.getId());
boolean candidateUserTestFound = false;
for (IdentityLink identityLink : taskIdentityLinks) {
if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getUserId() != null && identityLink.getGroupId() == null) {
if ("test".equals(identityLink.getUserId())) {
candidateUserTestFound = true;
}
}
}
assertFalse(candidateUserTestFound);
taskService.complete(task.getId());
assertProcessEnded(processInstance.getId());
// now test with changing the form key
ObjectNode infoNode = dynamicBpmnService.changeUserTaskCandidateUser("task1", "test", true);
dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskIdentityLinks = taskService.getIdentityLinksForTask(task.getId());
candidateUserTestFound = false;
for (IdentityLink identityLink : taskIdentityLinks) {
if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getUserId() != null && identityLink.getGroupId() == null) {
if ("test".equals(identityLink.getUserId())) {
candidateUserTestFound = true;
}
}
}
assertTrue(candidateUserTestFound);
taskService.complete(task.getId());
infoNode = dynamicBpmnService.getProcessDefinitionInfo(processDefinitionId);
dynamicBpmnService.changeUserTaskCandidateUser("task1", "test2", false, infoNode);
dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskIdentityLinks = taskService.getIdentityLinksForTask(task.getId());
candidateUserTestFound = false;
boolean candidateUserTest2Found = false;
for (IdentityLink identityLink : taskIdentityLinks) {
if (IdentityLinkType.CANDIDATE.equals(identityLink.getType()) && identityLink.getUserId() != null && identityLink.getGroupId() == null) {
if ("test".equals(identityLink.getUserId())) {
candidateUserTestFound = true;
} else if ("test2".equals(identityLink.getUserId())) {
candidateUserTest2Found = true;
}
}
}
assertTrue(candidateUserTestFound);
assertTrue(candidateUserTest2Found);
taskService.complete(task.getId());
assertProcessEnded(processInstance.getId());
}
Aggregations