Manipulating tasklist filters via Java API

When we deploy a process we would like to setup tasklist filters via the Java API. First we would like to delete certain filters and then create them anew. Currently we are facing these difficulties:

  1. Searching for filters by name
    It seams you can only search by id. If we try e.g.:

     FilterQuery query = filterService.createTaskFilterQuery().;
     query.filterName("some filter name");
     for (Object filter : filterService.list(null, query)) {
         filterService.deleteFilter(((Filter) filter).getId());
     }
    

    It throws a NPE. The same happens if we use an empty string for the first argument to list.

  2. Setting variables
    We would like to define variables to be displayed in the task list but we cannot figure out how.

We are currently using 7.5.2-ee.

Regarding your first question, can you please post the exception stack trace?

Of course:

02-Sep-2016 11:23:47.159 SEVERE [RMI TCP Connection(30)-127.0.0.1] org.camunda.commons.logging.BaseLogger.logError ENGINE-16004 Exception while closing command context: No filter found for id '': filter is null
 org.camunda.bpm.engine.exception.NullValueException: No filter found for id '': filter is null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.camunda.bpm.engine.impl.util.EnsureUtil.generateException(EnsureUtil.java:334)
    at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:49)
    at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:44)
    at org.camunda.bpm.engine.impl.cmd.AbstractExecuteFilterCmd.getFilter(AbstractExecuteFilterCmd.java:52)
    at org.camunda.bpm.engine.impl.cmd.AbstractExecuteFilterCmd.getFilterQuery(AbstractExecuteFilterCmd.java:63)
    at org.camunda.bpm.engine.impl.cmd.ExecuteFilterListCmd.execute(ExecuteFilterListCmd.java:37)
    at org.camunda.bpm.engine.impl.cmd.ExecuteFilterListCmd.execute(ExecuteFilterListCmd.java:24)
    at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
    at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:104)
    at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66)
    at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
    at org.camunda.bpm.engine.impl.FilterServiceImpl.list(FilterServiceImpl.java:73)
    at ch.visana.bpm.erfa.Application.setupFilters(Application.java:96)
    at ch.visana.bpm.erfa.Application.setup(Application.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.camunda.bpm.container.impl.deployment.PostDeployInvocationStep.performOperationStep(PostDeployInvocationStep.java:64)
    at org.camunda.bpm.container.impl.spi.DeploymentOperation.execute(DeploymentOperation.java:114)
    at org.camunda.bpm.container.impl.jmx.MBeanServiceContainer.executeDeploymentOperation(MBeanServiceContainer.java:156)
    at org.camunda.bpm.container.impl.spi.DeploymentOperation$DeploymentOperationBuilder.execute(DeploymentOperation.java:203)
    at org.camunda.bpm.container.impl.RuntimeContainerDelegateImpl.deployProcessApplication(RuntimeContainerDelegateImpl.java:94)
    at org.camunda.bpm.application.AbstractProcessApplication.deploy(AbstractProcessApplication.java:62)
    at org.camunda.bpm.application.impl.ServletProcessApplication.contextInitialized(ServletProcessApplication.java:131)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1648)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Oh, I see the problem. FilterService#list does not execute the FilterQuery. In fact, it executes the query that is associated with a Filter. Since you pass null as the filter id, you get an exception. In order to list all filters, execute FilterQuery#list.

Regarding your second question: The variable names of a filter are encoded in the filter’s properties (i.e. Filter#getProperties). I don’t know those properties from the top of my head. Perhaps, you can just create a filter via task list and then see what the properties are.

Thank you, that did the trick.

Since I had the same question and couldn’t find any documentation about it, here is what the Tasklist does:

{
"id": "ece0fd41-2ce9-11e8-9e51-02427a840083",
"name": "Compliance",
"resourceType": "Task",
"query": {
    "candidateGroup": "Compliance",
    "unassigned": "true"
},
"properties": {
    "description": "Inbox fĂĽr Compliance",
    "priority": 0,
    "color": "#555555",
    "refresh": false,
    "variables": [
    {
        "name": "name",
        "label": "Name"
    },
    {
        "name": "country",
        "label": "Land"
    },
    {
        "name": "businessPartnerType",
        "label": "Geschäftspartnerart"
    }
    ],
    "showUndefinedVariable": false
}
}

In Java properties is a Map<String, Object> and variables would look like this:

List<Map<String, String>> variables = new ArrayList<Map<String, String>>();
variables.add(ImmutableMap.of("name", "name", "label", "Name"));
variables.add(ImmutableMap.of("name", "country", "label", "Land"));
variables.add(ImmutableMap.of("name", "businessPartnerType", "label", "Geschäftspartnerart"));
1 Like