Problem with getting "startableByUser" processes

Hi,
I have a process where neither candateStarterGroups nor candateStarterUsers is defined, e.g.:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flowable="http://flowable.org/bpmn"
    xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
    xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
    expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/test">
    <process id="my-process">
        <startEvent id="start"/>
        <sequenceFlow id="flow1" sourceRef="start" targetRef="someTask"/>
        <userTask id="someTask" name="Flowable is awesome!"/>
        <sequenceFlow id="flow2" sourceRef="someTask" targetRef="end"/>
        <endEvent id="end"/>
    </process>
</definitions>

When I’m trying to query process definitions startable by some user, I expect to see this process definition, because it has no restrictions on who can start it.

Unit test:

package com.company;

import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.test.Deployment;
import org.flowable.engine.test.FlowableRule;
import org.junit.Rule;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;

public class MyUnitTest {

    @Rule
    public FlowableRule flowableRule = new FlowableRule();

    @Test
    @Deployment(resources = {"my-process.bpmn20.xml"})
    public void test() {
        List<ProcessDefinition> processDefinitions = flowableRule.getRepositoryService().createProcessDefinitionQuery()
                .startableByUser("someUser")
                .list();
        assertEquals(1, processDefinitions.size());
    }
}

But the query with startableByUser("someUser") condition returns nothing. Such queries return only processes where candidates are explicitly defined. Was it designed this way intentionally or it is a bug? Is there a way to query process definitions where no candidates are defined?

Hi,

Yes this is by design. When using startableByUser it checks for explicitly defined candidateStarterGroups and candidateStarterUsers.

You can also argue that not defining candidateStarterGroups or candidateStarterUsers means that this is a process definition that should not be started by anyone, perhaps a system process.

Currently there is no way to query process definitions where no candidates are defined. In order to check for that you would need to get the process definition and then you can use RepositoryService#getIdentityLinksForProcessDefinition(String) to get all the identity links for the definition and then check that that is an empty list (no candidates defined).

Cheers,
Filip

Hi Filip,
thank you for the answer an for the provided solution.
As I understand, by design, if no candidate is defined that means that this process should not be started by users at all, right?
What are best practices then to specify that this process can be started by any user? To have a separate group which contains all users and automatically add new users to it?

Exactly by design in the Java API it is like that.

Exactly, if you have a base group that all users belong to then you can assign this group to all users and also add new users to it.