Map<String, Object> filterProperties = new HashMap<String, Object>();
filterProperties.put("description", "Tasks assigned to me");
filterProperties.put("priority", -10);
addVariables(filterProperties);
TaskService taskService = engine.getTaskService();
TaskQuery query = taskService.createTaskQuery().taskAssigneeExpression("${currentUser()}");
Filter myTasksFilter = filterService.newTaskFilter().setName("My Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(myTasksFilter);
filterProperties.clear();
filterProperties.put("description", "Tasks assigned to my Groups");
filterProperties.put("priority", -5);
addVariables(filterProperties);
query = taskService.createTaskQuery().taskCandidateGroupInExpression("${currentUserGroups()}").taskUnassigned();
Filter groupTasksFilter = filterService.newTaskFilter().setName("My Group Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(groupTasksFilter);
// global read authorizations for these filters
Authorization globalMyTaskFilterRead = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GLOBAL);
globalMyTaskFilterRead.setResource(FILTER);
globalMyTaskFilterRead.setResourceId(myTasksFilter.getId());
globalMyTaskFilterRead.addPermission(READ);
authorizationService.saveAuthorization(globalMyTaskFilterRead);
Authorization globalGroupFilterRead = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GLOBAL);
globalGroupFilterRead.setResource(FILTER);
globalGroupFilterRead.setResourceId(groupTasksFilter.getId());
globalGroupFilterRead.addPermission(READ);
authorizationService.saveAuthorization(globalGroupFilterRead);
// management filter
filterProperties.clear();
filterProperties.put("description", "Tasks for Group Accounting");
filterProperties.put("priority", -5);
addVariables(filterProperties);
query = taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("accounting")).taskUnassigned();
Filter candidateGroupTasksFilter = filterService.newTaskFilter().setName("Accounting").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(candidateGroupTasksFilter);
Authorization managementGroupFilterRead = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
managementGroupFilterRead.setResource(FILTER);
managementGroupFilterRead.setResourceId(candidateGroupTasksFilter.getId());
managementGroupFilterRead.addPermission(READ);
managementGroupFilterRead.setGroupId("accounting");
authorizationService.saveAuthorization(managementGroupFilterRead);
// john's tasks
filterProperties.clear();
filterProperties.put("description", "Tasks assigned to John");
filterProperties.put("priority", -5);
addVariables(filterProperties);
query = taskService.createTaskQuery().taskAssignee("john");
Filter johnsTasksFilter = filterService.newTaskFilter().setName("John's Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(johnsTasksFilter);
// mary's tasks
filterProperties.clear();
filterProperties.put("description", "Tasks assigned to Mary");
filterProperties.put("priority", -5);
addVariables(filterProperties);
query = taskService.createTaskQuery().taskAssignee("mary");
Filter marysTasksFilter = filterService.newTaskFilter().setName("Mary's Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(marysTasksFilter);
// peter's tasks
filterProperties.clear();
filterProperties.put("description", "Tasks assigned to Peter");
filterProperties.put("priority", -5);
addVariables(filterProperties);
query = taskService.createTaskQuery().taskAssignee("peter");
Filter petersTasksFilter = filterService.newTaskFilter().setName("Peter's Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(petersTasksFilter);
// all tasks
filterProperties.clear();
filterProperties.put("description", "All Tasks - Not recommended to be used in production :)");
filterProperties.put("priority", -5);
addVariables(filterProperties);
query = taskService.createTaskQuery();
Filter allTasksFilter = filterService.newTaskFilter().setName("All Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(allTasksFilter);
}