ucReportSetFilters

Purpose

ucReportSetFilters generally adds filters and filter criteria to a report before the query is processed

Applies To

Search & Reporting screens

Signature

public void ucReportSetFilters (
      FilterGroup fg)

Notes

This affects all types of reports (summary, list, charts), allowing data to be segregated efficiently, for example by Customer or Privacy.

Example

public void ucReportSetFilters (FilterGroup fg,
                                    String mode) {
        // requirement: Customer-role user can only see own (originator) issue
        // Get current session and user
        SesameSession session = SesameSession.getSession();
        String userId = session.getUserId();
        String userRole = session.getUserRole();

        if (! "GUEST".equals(userRole) )
            return;
        
        // Get current filters
        ArrayList filters = fg.getFilters();

        // Create originator-specific filter
        Filter originator = new Filter("ORIGINATOR");
        originator.setOperator("in");
        originator.setConjunction("AND");
        ArrayList criteria = new ArrayList();
        criteria.add(userId);

        try {
            originator.setFilterCriteria(criteria);
        } catch (Exception e) {}
        
        // If no filters exist, then just add originator filter
        if (filters.isEmpty() ) {
            filters.add(originator);
            fg.setFilters(filters);
            return;
        }
        // When filters already exist, need to add originator filter to all
        // "AND" filter sets (standard or advanced)

        // Iterate through current filters and add the originator filter to
        // the end of "AND" only sets, in case
        // any filters have "OR" conjuction (which cause groups of "AND"
        // filters to be evaluated together due to precedence rules)
        ArrayList newFilters = new ArrayList();

        for (int i = 0; i