ucFilterUserPopup

Purpose

ucFilterUserPopup is called when the USER_LIST_DISPLAY behavior setting has a value of POPUP, and can be used to filter the results of a user search by modifying the TreeMap parameter.

Applies To

Field Rendering Methods

Signature

public void ucFilterUserPopup (SesameSession session,
                               String ddName,
                               TreeMap userMap)  

Notes

Example

 public void ucFilterUserPopup (SesameSession session, 
                                String ddName,
                                TreeMap userMap) {
        String role = session.getUserRole();

        // only perform check for Customer role
        if (! "CLIENT".equals(role) ) return;

        // For Customer (CLIENT) role, filter search results to only users
        // with same Company Name as the CUSTOMER_ID field value on the record
        // NOTE: THIS FILTERING AFFECTS ALL USER FIELDS, AS OPPOSED TO THE
        // SPECIFIC FIELDS LISTED IN THE checkCustomerFields METHOD.
        HashMap tabVals = (HashMap) session.getAttribute("TAB_VALS");
        String companyName = null;
        String customerUdfListId = null;

        // first, get the Company Name from the CUSTOMER_ID field
        if (tabVals != null) {
            customerUdfListId = (String) tabVals.get("CUSTOMER_ID");
            Connection con = null;

            try {
                con = Z.pool.getConnection("ucFilterUserPopup");
                UdfList ul = UdfList.getReference(con, customerUdfListId);
                companyName = ul.getTitle();
            }
            catch (Exception e) {
                ErrorWriter.write(e, ErrorWriter.LOGERR);
            }
            finally {
                Z.pool.close(con);
            }
        }
        // otherwise, get the Company Name from the current user
        else {
            SecurityUser su = (SecurityUser) session.getAttribute("USER");

            if (su != null) {
                companyName = su.getCompanyName();
            }
        }
        if (companyName == null) {
            Z.log.writeToLog(Z.log.WARN, 
            "ucFilterUserPopup: NO COMPANY NAME DETECTED FOR USER SEARCH FILTERING");
            userMap.clear();
        }
        // go through list of users and remove the ones not matching the Company Name
        Iterator i = userMap.keySet().iterator();
        ArrayList removeList = new ArrayList();

        while (i.hasNext() ) {
            String key = (String) i.next();
            HashMap hm = (HashMap) userMap.get(key);
            String userCompany = (String) hm.get("COMPANY_NAME");

            if (! companyName.equals(userCompany) ) {
                removeList.add(key);
            }
        }
        for (int j = 0; j < removeList.size(); j++) {
            userMap.remove(removeList.get(j));
        }
    }