Hi at all,
Currently I am generating filters in my java programm. For this I wrote a method that generates filters based on an easy filter model:
private void createFilter(Filter filter){
FilterService filterService = processEngine.getFilterService();
Map<String, Object> filterProperties = new HashMap<String, Object>();
filterProperties.put(“description”, filter.getDescription());
filterProperties.put(“priority”, filter.getPriority());
filterProperties.put(“refresh”,filter.getAutoRefresh());
TaskService taskService = processEngine.getTaskService();
List variables = new ArrayList();
filterProperties.put(“variables”, variables);
TaskQuery query;
if(filter.getExpressionType().equals(“taskCandidateGroupInExpression”)){
query = taskService.createTaskQuery().taskCandidateGroupInExpression(filter.getExpression()).taskUnassigned();
} else{
query = taskService.createTaskQuery().taskAssigneeExpression(filter.getExpression());
}
Filter myTasksFilter = filterService.newTaskFilter().setName(filter.getName()).setProperties(filterProperties).setOwner(filter.getOwner()).setQuery(query);
filterService.saveFilter(myTasksFilter);
}
This method is working fine. However I want now to generate filters with some predefined criterias. In the method is allready a list for the variables, that I can fill if I want to have some variables (for now I am not using it). What can I do to implement some criterias?
For example, I want to generate a filter, that has a criteria with the key “Task Definition Key” and the value “process_step_one”. How could I do this?
Thanks for your help
Okay I found the solution!
For everybody who is interested in this:
If you want to generate a criteria with the key “Task Definition Key” and the value “process_step_one”, you need a method like this:
private void createFilter(Filter filter){
FilterService filterService = processEngine.getFilterService();
Map<String, Object> filterProperties = new HashMap<String, Object>();
filterProperties.put(“description”, filter.getDescription());
filterProperties.put(“priority”, filter.getPriority());
filterProperties.put(“refresh”,filter.getAutoRefresh());
TaskService taskService = processEngine.getTaskService();
List variables = new ArrayList();
this.addVariable(variables,“initiator”,“initiator”);
filterProperties.put(“variables”, variables);
TaskQuery query = null;
query = taskService.createTaskQuery().taskDefinitionKey(“process_step_one”);
Filter myTasksFilter = filterService.newTaskFilter().setName(filter.getName()).setProperties(filterProperties).setOwner(filter.getOwner()).setQuery(query);
filterService.saveFilter(myTasksFilter);
}
protected void addVariable(List variables, String name, String label) {
Map<String, String> variable = new HashMap<String, String>();
variable.put(“name”, name);
variable.put(“label”, label);
variables.add(variable);
}
If you do it like this, your Filter model would look like this:
@Setter
@Getter
@AllArgsConstructor
public class Filter {
private String description;
private int priority;
private String expression;
private String name;
private String owner;
private String expressionType;
private Boolean autoRefresh;
}
The most important line I was missing is this line:
query = taskService.createTaskQuery().taskDefinitionKey("process_step_one");
Regards,
Marvin
1 Like
Niall
June 17, 2020, 1:14pm
3
Thanks for posting your solution