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:
In the Modeling Perspective import the example model WorklistFilterModel or create a model with the following elements:

Figure: Structured Type

Figure: Descriptor for Location

Figure: Descriptor for DepCreationDate
In the Administration perspective open the Participant Manager. Create the following three users:
01/01/201609/01/2016
Figure: Created users
Assign these users as follows:

Figure: Role assignments
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:
DepartmentNorth and DepartmentSouth, the worklist
filter filters for all values of attribute DepartmentInfo.Location that contain the terms
North or South.DepartmentNorth, the worklist filter
filters for all values of attribute DepartmentInfo.Location that contain the term
North.DepartmentSouth, the worklist filter
filters for all values of attribute DepartmentInfo.Location that contain the term
South.DepartmentNorth nor grant DepartmentSouth, no
filter is applied.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.
Perform the following steps:
North, South and OtherlocationFilter=org.eclipse.stardust.examples.filter.LocationFilter

Figure: Worklist Configuration

Figure: Worklist of Master of the Universe
North.

Figure: Worklist of Croft Lara
South.

Figure: Worklist of Daisy Duck
North and South. Also, none of the
three users can see activities with location Other.

Figure: Worklist of Cityman Frank
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:
Perform the following steps to run the example with two filters:
North - 05/01/2016North - 09/09/2016North - 12/01/2015South - 05/01/2016South - 09/09/2016South - 12/01/2015Other - any datelocationFilter=org.eclipse.stardust.examples.filter.LocationFilter,cdateFilter=org.eclipse.stardust.examples.filter.CreationDateFilter

Figure: Worklist Configuration

Figure: Worklist of Master of the Universe
North and department creation earlier than her Valid From
date 01/01/2016.

Figure: Worklist of Croft Lara
South and department creation earlier than her Valid From
date 09/01/2016.

Figure: Worklist of Daisy Duck
North and South, independent
from DepCreationDate as no Valid From value is set for this user.

Figure: Worklist of Cityman Frank