Creating and Applying a Worklist Filter

In this tutorial we create a custom Worklist Filter class and apply the worklist filter from the Portal Configuration. Then we create a second Worklist Filter and combine it with the first one.

You find the example source code as well as the complete example model in the following ZIP file in folder portal-configuration:

Creating the Model

In the Modeling Perspective import the example model WorklistFilterModel or create a model with the following elements:

Assigning Users

In the Administration perspective open the Participant Manager. Create the following three users:

Created users
Figure: Created users

Assign these users as follows:

Role assignments
Figure: Role assignments

Creating a Filter Provider to filter for Data Attribute Location

Now we create a Java file named LocationFilter.java to filter for attribute Location of structured data DepartmentInfo with specific values depending on the grant of the logged-in user. You can import this example class from the example ZIP file mentioned above.

package org.eclipse.stardust.examples.filter;

import java.util.Iterator;
import java.util.List;

import org.eclipse.stardust.ui.web.viewscommon.beans.SessionContext;
import org.eclipse.stardust.ui.web.viewscommon.common.provider.AbstractFilterProvider;
import org.eclipse.stardust.engine.api.query.DataFilter;
import org.eclipse.stardust.engine.api.query.FilterAndTerm;
import org.eclipse.stardust.engine.api.query.FilterOrTerm;
import org.eclipse.stardust.engine.api.query.Query;
import org.eclipse.stardust.engine.api.runtime.Grant;
import org.eclipse.stardust.engine.api.runtime.User;


public class LocationFilter extends AbstractFilterProvider
{
   private static final long serialVersionUID = 1L;

   /* (non-Javadoc)
    * @see org.eclipse.stardust.ui.web.client.common.spi.IFilterProvider#applyFilter(org.eclipse.stardust.engine.api.query.Query)
    */
   public void applyFilter(Query query)
   {
      System.out.println("Applying Filter Provider - LocationFilter.applyFilter()");
      User user = SessionContext.findSessionContext().getUser();
      
      boolean depNorth = false;
      boolean depSouth = false;

      List<Grant> grants = (List<Grant>) user.getAllGrants();
      Iterator<Grant> iterator = grants.iterator();
      while (iterator.hasNext())
      {
         Grant grant = iterator.next();

         if (grant.getId().equalsIgnoreCase("DepartmentNorth"))
         {
            depNorth = true;
         }

         if (grant.getId().equalsIgnoreCase("DepartmentSouth"))
         {
            depSouth = true;
         }
      }

      System.out.println("depNorth = " + depNorth + ":: depSouth = " + depSouth);
      
      if (depNorth && depSouth)
      {
         FilterOrTerm filter = query.getFilter().addOrTerm();
         filter.add(DataFilter.like("DepartmentInfo", "Location", "%North%", false));
         filter.add(DataFilter.like("DepartmentInfo", "Location", "%South%", false));
      }
      else if (depNorth)
      {
         FilterAndTerm filter = query.getFilter().addAndTerm();
         filter.add(DataFilter.like("DepartmentInfo", "Location", "%North%", false));
      }
      else if (depSouth)
      {
         FilterAndTerm filter = query.getFilter().addAndTerm();
         filter.add(DataFilter.like("DepartmentInfo", "Location", "%South%", false));
      }
      else
      {
         System.out.println("NOT Applying any Filter");
      }
   }
}

The filter works as follows:

Adding the Java File

Add the LocationFilter.java file to the classpath of your Web project. Make sure that the LocationFilter.java file resides under the package named org.eclipse.stardust.examples.filter. Note that you need to restart your server to make the class available.

Running the Example and Applying the Location Filter

Perform the following steps:

  1. Deploy your model
  2. Login with user motu (Master of the Universe)
  3. Start a few instances of process Collect Customer Data of and enter locations as North, South and Other
  4. Suspend and save these instances
  5. Go to the Worklist section in the Configuration view and specify the following filter:
    locationFilter=org.eclipse.stardust.examples.filter.LocationFilter

    Worklist - Filter Provider
    Figure: Worklist Configuration

  6. Click Save. For details on the worklist configuration, please refer to chapter Configuring Worklists in the Stardust Portal documentation.
  7. User Master of the Universe can view all activities in his worklist:

    Worklist - Master of the Universe
    Figure: Worklist of Master of the Universe

  8. Login with user Croft Lara and open her worklist. Note that Croft Lara can see activities with location North.

    Worklist - Croft Lara
    Figure: Worklist of Croft Lara

  9. Login with user Daisy Duck and open her worklist. Note that Daisy Duck can see activities with location South.

    Worklist - Daisy Duck
    Figure: Worklist of Daisy Duck

  10. Login with user Cityman Frank and open his worklist. Note that Cityman Frank can see activities of both the locations with values North and South. Also, none of the three users can see activities with location Other.

    Worklist - Cityman Frank
    Figure: Worklist of Cityman Frank

Creating a Filter Provider to filter for Department Creation Data

Now we create an additional filter which we will apply combined with our location filter. This filter class named CreationDateFilter.java filters simply checks if the department was created before the user validation date.

     
package org.eclipse.stardust.examples.filter;

import java.util.Date;

import org.eclipse.stardust.engine.api.query.DataFilter;
import org.eclipse.stardust.engine.api.query.FilterAndTerm;

import org.eclipse.stardust.engine.api.query.Query;
import org.eclipse.stardust.engine.api.runtime.User;
import org.eclipse.stardust.ui.web.viewscommon.beans.SessionContext;
import org.eclipse.stardust.ui.web.viewscommon.common.provider.AbstractFilterProvider;


public class CreationDateFilter extends AbstractFilterProvider
{
   private static final long serialVersionUID = 1L;

   public void applyFilter(Query query)
   {
      System.out.println("Applying Filter Provider - CreationDateFilter.applyFilter()");
      
      User user = SessionContext.findSessionContext().getUser();
      Date datetest = user.getValidFrom();
      
      /* Create filter to check if user validation date is before the department creation date */
      if (datetest != null) {
         FilterAndTerm filter = query.getFilter().addAndTerm();
       filter.add(DataFilter.lessThan("DepCreationDate", datetest));
      }
      else
      {
          System.out.println("in CityFilter: NOT Applying any Filter");
      }     
   }
}

This filter works as follows:

Running the Example and Applying both Filters

Perform the following steps to run the example with two filters:

  1. Deploy your model
  2. Login with user motu (Master of the Universe)
  3. Start a few instances of process Collect Customer Data of and enter the following combinations for Location and DepCreationDate:
  4. Suspend and save these instances
  5. Specify the following filters in the Configuration View and click Save:
    locationFilter=org.eclipse.stardust.examples.filter.LocationFilter,cdateFilter=org.eclipse.stardust.examples.filter.CreationDateFilter

    Worklist - Filter Provider
    Figure: Worklist Configuration

  6. User Master of the Universe can view all activities in his worklist:

    Worklist - Master of the Universe
    Figure: Worklist of Master of the Universe

  7. Login with user Croft Lara and open her worklist. Note that Croft Lara can see activities with location North and department creation earlier than her Valid From date 01/01/2016.

    Worklist - Croft Lara
    Figure: Worklist of Croft Lara

  8. Login with user Daisy Duck and open her worklist. Note that Daisy Duck can see activities with location South and department creation earlier than her Valid From date 09/01/2016.

    Worklist - Daisy Duck
    Figure: Worklist of Daisy Duck

  9. Login with user Cityman Frank and open his worklist. Note that Cityman Frank can see activities where Location has values North and South, independent from DepCreationDate as no Valid From value is set for this user.

    Worklist - Cityman Frank
    Figure: Worklist of Cityman Frank