3 Replies Latest reply on Jun 2, 2008 2:33 AM by Mansingh Shitole

    How to filter TaskList items ?

    Frank Newbie

      Dear all,
      I have a web application which displays a TaskList for the user. As new feature this application needs to filter the tasklist with all possible fields ( actor, date, isOpen, Task name ..etc)

      I know that hibernate has Filters which can be activated on a Class/Collections so the only way to do this is unzipping JBPM hibernate files.......changing "TaskInstance.hbm.xml" adding a Query and filters to it......

      correct ? or maybe there's a simple solution ?
      Thanks for your help

        • 1. Re: How to filter TaskList items ?
          David Roberts Apprentice

          In my customized Workflow web application, I get the Tasks I want in my action class. Here are two methods that may help or give you ideas.
          I simply add the retrieved list as a request attribute, and then code my JSP page displays whatever I want it to.



          /**
           * Gets all task instances that a user with the given actor id could claim.
           * @return List of jbpm task instances.
           */
           public static List getUnClaimedTaskInstancesForActorId (JbpmContext jbpmContext, String actorId) {
           Session session = jbpmContext.getSession();
          
           //create list of possible id's (this includes groups) that
           //belong to the current user.
           List actorsList = new ArrayList();
           actorsList.add(actorId);
           IdentitySession identitySession = new IdentitySession(session);
           org.jbpm.identity.User jbpmUser = identitySession.getUserByName(actorId);
           Iterator i = jbpmUser.getMemberships().iterator();
           while(i.hasNext()){
           Membership m = (Membership) i.next();
           actorsList.add(m.getGroup().getName());
           }
           List pooledTaskInstances = jbpmContext.getTaskMgmtSession().findPooledTaskInstances(actorsList);
           List jbpmTaskInstanceList = session.createQuery("from org.jbpm.taskmgmt.exe.TaskInstance ti where ti.start is null and ti.end is null and actorId = '"+actorId+"'").list();
           //add pooledTaskInstances to taskList
           jbpmTaskInstanceList.addAll(pooledTaskInstances);
          
           //TODO sort jbpmTaskInstanceList by task instance id
          
           return jbpmTaskInstanceList;
           }


          /**
           * Retrieves a list of TaskInstance objects for a given user, that he has claimed/started.
           * @param actorId
           * @return
           */
           private List getClaimedTasks(String actorId) {
           Session session = jbpmContext.getSession();
           List jbpmTaskInstanceList = session.createQuery("from org.jbpm.taskmgmt.exe.TaskInstance ti where ti.start is not null and ti.end is null and actorId = '"+actorId+"'").list();
           return jbpmTaskInstanceList;
           }


          I also have some more complex method which are relevant to my web app, like retrieving tasks for everyone in your team etc. But that's all dependant on your identity component.



          • 2. Re: How to filter TaskList items ?
            Frank Newbie

            Hello,
            well thanks for your reply.
            The main difficulty in my code is that the front-end can select as many filter as he wish....or maybe even none.
            In plain SQL you have to build SQL dynamically checking if the filter was set then you add "AND param = :parameter".

            Anyway I just managed to run it:

            Here's the TaskInstance with one filter in it:

            <?xml version="1.0"?>
            
            <!DOCTYPE hibernate-mapping PUBLIC
             "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
             "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
            
            <hibernate-mapping auto-import="false" default-access="field">
            
             <class name="org.jbpm.taskmgmt.exe.TaskInstance"
             table="JBPM_TASKINSTANCE"
             discriminator-value="T">
             <id name="id" column="ID_"><generator class="native" /></id>
             <discriminator type="char" column="CLASS_"/>
             <version name="version" column="VERSION_" />
            
             <property name="name" column="NAME_" />
             <property name="description" column="DESCRIPTION_" length="4000">
             <type name="string_max">
             <param name="length">4000</param>
             </type>
             </property>
             <property name="actorId" column="ACTORID_" index="IDX_TASK_ACTORID"/>
             <property name="create" column="CREATE_" />
             <property name="start" column="START_" />
             <property name="end" column="END_" />
             <property name="dueDate" column="DUEDATE_" />
             <property name="priority" column="PRIORITY_" />
             <property name="isCancelled" column="ISCANCELLED_" />
             <property name="isSuspended" column="ISSUSPENDED_" />
             <property name="isOpen" column="ISOPEN_" />
             <property name="isSignalling" column="ISSIGNALLING_" />
             <property name="isBlocking" column="ISBLOCKING_" />
            
            
            
             <many-to-one name="task"
             column="TASK_"
             foreign-key="FK_TASKINST_TASK"
             index="IDX_TASKINST_TSK"/>
             <many-to-one name="token"
             column="TOKEN_"
             foreign-key="FK_TASKINST_TOKEN"
             index="IDX_TASKINST_TOKN"/>
             <many-to-one name="processInstance"
             column="PROCINST_"
             foreign-key="FK_TSKINS_PRCINS"
             index="IDX_TASKINST_TSK"/>
             <many-to-one name="swimlaneInstance"
             column="SWIMLANINSTANCE_"
             foreign-key="FK_TASKINST_SLINST"
             index="IDX_TSKINST_SLINST" />
             <many-to-one name="taskMgmtInstance"
             column="TASKMGMTINSTANCE_"
             foreign-key="FK_TASKINST_TMINST"
             index="IDX_TSKINST_TMINST"/>
            
             <map name="variableInstances" cascade="all">
             <key column="TASKINSTANCE_" foreign-key="FK_VAR_TSKINST"/>
             <index type="string" column="NAME_" />
             <one-to-many class="org.jbpm.context.exe.VariableInstance" />
             </map>
             <set name="pooledActors"
             cascade="all"
             table="JBPM_TASKACTORPOOL">
             <key column="TASKINSTANCE_" foreign-key="FK_TASKACTPL_TSKI"/>
             <many-to-many class="org.jbpm.taskmgmt.exe.PooledActor" column="POOLEDACTOR_" />
             </set>
             <list name="comments" cascade="all" >
             <key column="TASKINSTANCE_" />
             <index column="TASKINSTANCEINDEX_" />
             <one-to-many class="org.jbpm.graph.exe.Comment" />
             </list>
            
             <filter name="activatedFilter" condition=":activatedParam = NAME_"/>
            
             </class>
            
            <filter-def name="activatedFilter">
             <filter-param name="activatedParam" type="string"/>
             </filter-def>
            
            </hibernate-mapping>


            I have replaced the file in the jbpm-jpdl.jar and then from my Servlet:

            ArrayList array = new ArrayList();
             JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
             JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
            
             Session session = jbpmContext.getSession();
             session.enableFilter("activatedFilter").setParameter("activatedParam", "TaskRisolta");
             String sqlParent = "from org.jbpm.taskmgmt.exe.TaskInstance";
            
            
             Query queryParent = session.createQuery(sqlParent);
            
            
             List list = queryParent.list();

            In this example I'm using a filter on the TaskName, now I need to add also filter for all other columns.

            A bit tough but I managed to do it !
            Thanks
            Francesco

            • 3. Re: How to filter TaskList items ?
              Mansingh Shitole Newbie

              I need to query for pooledactors according to specific task, through jsf..ie xhtml files and wanted to show result in jsf forms..so how I can call these methods from jsf files..please help..

              Thanking you,
              --Mansingh Shitole