I’m about 3/4 way down the Getting Started guide:
Getting Started · Flowable Open Source Documentation
When I run the code, the task query returns empty and I see
You have 0 tasks:
printed on the console.
Following is my code so far. What could I be missing?
ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
.setJdbcUrl("jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1")
.setJdbcUsername("sa")
.setJdbcPassword("")
.setJdbcDriver("org.h2.Driver")
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
ProcessEngine processEngine = cfg.buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("holiday-request.bpmn20.xml")
.deploy();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.deploymentId(deployment.getId())
.singleResult();
System.out.println("Found process definition: " + processDefinition.getName());
Scanner scanner = new Scanner(System.in);
System.out.println("Who are you?");
String employee = scanner.nextLine();
System.out.println("How many holidays do you want to request?");
Integer noOfHolidays = Integer.valueOf(scanner.nextLine());
System.out.println("Why do you need them?");
String description = scanner.nextLine();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("employee", employee);
variables.put("noOfHolidays", noOfHolidays);
variables.put("description", description);
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holidayRequest", variables);
TaskService taskService = processEngine.getTaskService();
List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("managers").list();
System.out.println("You have " + tasks.size() + " tasks:");
for (int i=0; i<tasks.size(); i++) {
System.out.println((i + 1) + ") " + tasks.get(i).getName());
}
System.out.println("Which tasks would you like to complete?");
int taskIndex = Integer.valueOf(scanner.nextLine());
Task task = tasks.get((taskIndex - 1));
Map<String, Object> processVariables = taskService.getVariables(task.getId());
System.out.println(
processVariables.get("employee") +
" wants " +
processVariables.get("noOfHolidays") +
" of holidays. Do you approve this?"
);
boolean approved = scanner.nextLine().toLowerCase().equals("y");
variables = new HashMap<String, Object>();
variables.put("approved", approved);
taskService.complete(task.getId(), variables);