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.service.impl;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.kfs.integration.cg.ContractsAndGrantsModuleService;
020    import org.kuali.kfs.sys.KFSPropertyConstants;
021    import org.kuali.kfs.sys.context.SpringContext;
022    import org.kuali.rice.kim.bo.Person;
023    
024    /**
025     * Custom access permission evaluator for principal investigator restrictions
026     */
027    public class PrincipalInvestigatorAccessPermissionEvaluatorImpl extends AccessPermissionEvaluatorImpl {
028    
029        /**
030         * Matches on accounts for which the person is a principal investigator (project director)
031         * 
032         * @see org.kuali.kfs.sec.service.impl.AccessPermissionEvaluatorImpl#isMatch(java.lang.String, java.lang.String)
033         */
034        @Override
035        protected boolean isMatch(String matchValue, String value) {
036            boolean match = false;
037    
038            String chartCode = (String) otherKeyFieldValues.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
039    
040            Person principalInvestigator = SpringContext.getBean(ContractsAndGrantsModuleService.class).getProjectDirectorForAccount(chartCode, value);
041            if (StringUtils.equals(person.getPrincipalId(), principalInvestigator.getPrincipalId())) {
042                match = true;
043            }
044    
045            return match;
046        }
047    
048    }