ucReportSetFilters

Purpose

ucReportSetFilters adds filters and filter criteria to a report before the query is processed.  This method is also called when a Related Issue Display is displayed within an add or edit screen.

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 < filters.size(); i++) {
            Filter f = (Filter) filters.get(i);
            String conjunction = f.getConjunction();

            if ("OR".equals(conjunction) ) {
                // Found a filter with an "OR" conjunction:
                // add originator filter
                newFilters.add(originator);
            }
            newFilters.add(f);
        }

        // Add originator filter as last filter
        newFilters.add(originator);

        // Set report filters to newly modified ones
        fg.setFilters(newFilters);
    }