use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class TaskIdentityLinksTest method testCustomLinkGroupLink.
@Deployment(resources = "org/activiti/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testCustomLinkGroupLink() {
runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
String taskId = taskService.createTaskQuery().singleResult().getId();
taskService.addGroupIdentityLink(taskId, "muppets", "playing");
List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
IdentityLink identityLink = identityLinks.get(0);
assertThat(identityLink.getGroupId()).isEqualTo("muppets");
assertThat(identityLink.getUserId()).as("kermit").isNull();
assertThat(identityLink.getType()).isEqualTo("playing");
assertThat(identityLink.getTaskId()).isEqualTo(taskId);
assertThat(identityLinks).hasSize(1);
taskService.deleteGroupIdentityLink(taskId, "muppets", "playing");
assertThat(taskService.getIdentityLinksForTask(taskId)).hasSize(0);
}
use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class TaskIdentityLinksTest method testCandidateGroupLink.
@Deployment(resources = "org/activiti/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testCandidateGroupLink() {
runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
String taskId = taskService.createTaskQuery().singleResult().getId();
taskService.addCandidateGroup(taskId, "muppets");
List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
IdentityLink identityLink = identityLinks.get(0);
assertThat(identityLink.getGroupId()).isEqualTo("muppets");
assertThat(identityLink.getUserId()).as("kermit").isNull();
assertThat(identityLink.getType()).isEqualTo(IdentityLinkType.CANDIDATE);
assertThat(identityLink.getTaskId()).isEqualTo(taskId);
assertThat(identityLinks).hasSize(1);
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
List<Event> taskEvents = taskService.getTaskEvents(taskId);
assertThat(taskEvents).hasSize(1);
Event taskEvent = taskEvents.get(0);
assertThat(taskEvent.getAction()).isEqualTo(Event.ACTION_ADD_GROUP_LINK);
List<String> taskEventMessageParts = taskEvent.getMessageParts();
assertThat(taskEventMessageParts.get(0)).isEqualTo("muppets");
assertThat(taskEventMessageParts.get(1)).isEqualTo(IdentityLinkType.CANDIDATE);
assertThat(taskEventMessageParts).hasSize(2);
}
taskService.deleteCandidateGroup(taskId, "muppets");
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
List<Event> taskEvents = taskService.getTaskEvents(taskId);
Event taskEvent = findTaskEvent(taskEvents, Event.ACTION_DELETE_GROUP_LINK);
assertThat(taskEvent.getAction()).isEqualTo(Event.ACTION_DELETE_GROUP_LINK);
List<String> taskEventMessageParts = taskEvent.getMessageParts();
assertThat(taskEventMessageParts.get(0)).isEqualTo("muppets");
assertThat(taskEventMessageParts.get(1)).isEqualTo(IdentityLinkType.CANDIDATE);
assertThat(taskEventMessageParts).hasSize(2);
assertThat(taskEvents).hasSize(2);
}
assertThat(taskService.getIdentityLinksForTask(taskId)).hasSize(0);
}
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 SerializePOJOJsonTest method testJsonVarInExpression.
@Deployment
public void testJsonVarInExpression() throws Exception {
Map<String, Object> vars = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("assignee", "bob");
map.put("category", "test");
Map<String, Object> mapInMap = new HashMap<String, Object>();
mapInMap.put("user", "bob");
map.put("mapInMap", mapInMap);
vars.put("userMap", map);
List<String> list = asList("bob", "john", "hannah");
vars.put("userCollection", list);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJsonVarInExpression", vars);
String taskId = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult().getId();
taskService.complete(taskId);
taskId = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult().getId();
taskService.getIdentityLinksForTask(taskId).stream().forEach(new Consumer<IdentityLink>() {
@Override
public void accept(IdentityLink i) {
if ("candidate".equals(i.getType())) {
assertThat(i.getUserId()).isEqualTo("bob");
}
}
});
taskService.complete(taskId);
HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
assertThat(task.getAssignee()).isEqualTo("bob");
assertThat(task.getCategory()).isEqualTo("test");
}
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;
}
}
}
assertThat(candidateGroupTestFound).isFalse();
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;
}
}
}
assertThat(candidateGroupTestFound).isTrue();
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;
}
}
}
assertThat(candidateGroupTestFound).isTrue();
assertThat(candidateGroupTest2Found).isTrue();
taskService.complete(task.getId());
assertProcessEnded(processInstance.getId());
}
Aggregations