001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.sec.businessobject.lookup;
017    
018    import java.util.List;
019    import java.util.Map;
020    
021    import org.kuali.kfs.coa.businessobject.lookup.KualiAccountLookupableHelperServiceImpl;
022    import org.kuali.kfs.sec.SecKeyConstants;
023    import org.kuali.kfs.sec.service.AccessSecurityService;
024    import org.kuali.kfs.sec.util.SecUtil;
025    import org.kuali.kfs.sys.KFSConstants;
026    import org.kuali.rice.kns.util.GlobalVariables;
027    
028    
029    /**
030     * Lookupable helper that provides Access Security integration
031     */
032    public class AccessSecurityAccountLookupableHelperServiceImpl extends KualiAccountLookupableHelperServiceImpl {
033        protected AccessSecurityService accessSecurityService;
034    
035        /**
036         * Gets search results and passes to access security service to apply access restrictions
037         * 
038         * @see org.kuali.rice.kns.lookup.LookupableHelperService#getSearchResults(java.util.Map)
039         */
040        public List getSearchResults(Map<String, String> fieldValues) {
041            List results = super.getSearchResults(fieldValues);
042    
043            int resultSizeBeforeRestrictions = results.size();
044            accessSecurityService.applySecurityRestrictionsForLookup(results, GlobalVariables.getUserSession().getPerson());
045    
046            SecUtil.compareListSizeAndAddMessageIfChanged(resultSizeBeforeRestrictions, results, SecKeyConstants.MESSAGE_LOOKUP_RESULTS_RESTRICTED);
047    
048            return results;
049        }
050    
051        /**
052         * Gets search results and passes to access security service to apply access restrictions
053         * 
054         * @see org.kuali.rice.kns.lookup.LookupableHelperService#getSearchResultsUnbounded(java.util.Map)
055         */
056        public List getSearchResultsUnbounded(Map<String, String> fieldValues) {
057            List results = super.getSearchResultsUnbounded(fieldValues);
058    
059            int resultSizeBeforeRestrictions = results.size();
060            accessSecurityService.applySecurityRestrictionsForLookup(results, GlobalVariables.getUserSession().getPerson());
061            
062            SecUtil.compareListSizeAndAddMessageIfChanged(resultSizeBeforeRestrictions, results, SecKeyConstants.MESSAGE_LOOKUP_RESULTS_RESTRICTED);
063    
064            return results;
065        }
066    
067        /**
068         * Sets the accessSecurityService attribute value.
069         * 
070         * @param accessSecurityService The accessSecurityService to set.
071         */
072        public void setAccessSecurityService(AccessSecurityService accessSecurityService) {
073            this.accessSecurityService = accessSecurityService;
074        }
075    
076    }